Solved

How to add/enable header X-Trino-User for ADO.NET Provider for Presto

  • 20 November 2023
  • 2 replies
  • 91 views

Userlevel 3
Badge

I’m getting the following exception when trying to run the following code.

Is there a way to enable or set the HTTP Header X-Trino-User?

PrestoConnection connection = new PrestoConnection($"Server={_configuration["TrinoServerIP"]};Port={_configuration["TrinoServerPort"]};");

connection.Open();

string sql = "SELECT * FROM hive.default.customer";

PrestoCommand cmd = new PrestoCommand(sql, connection);

PrestoDataReader rdr = cmd.ExecuteReader();

while (rdr.Read())
{
Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["Id"], rdr["Name"]));
}
 PrestoAdo
 Source: TrinoClientTests.cs line 91
 Duration: 1.4 sec

Message: 
Test method Juniper.Test.Trino.TrinoClientTests.PrestoAdo threw exception:
System.Data.CData.Presto.PrestoException: [500] Could not execute the specified command: HTTP protocol error. 401 Basic authentication or X-Trino-User must be sent. ---> oro230j.TC: HTTP protocol error. 401 Basic authentication or X-Trino-User must be sent.

Stack Trace: 
LdJ.j(Lax[] , Int32 , Int32 )
LdJ.n()
RUC.Nd()
RUx.Nd()
RTG.a(RUx )
RTN.FJ()
RTG.NS()
KJ.U(SQLQuery , Int32 , RRq )
KJ.d(IDataStatement , SQLQuery , QueryParameterCollection , Int32 , String , LeW )
RUJ.ExecuteQuery(IDataStatement , QueryParameterCollection , Int32 )
RUG.ExecuteQuery(IDataStatement , QueryParameterCollection , Int32 )
LTx.ExecuteQuery(IDataStatement , QueryParameterCollection , Int32 )
ZW.ExecuteQuery(IDataStatement , QueryParameterCollection , Int32 )
yN.ExecuteQuery(IDataStatement , QueryParameterCollection , Int32 )
RIe.FW()
RIh.dd()
SF.pg(QueryParameterCollection )
PrestoCommand.ExecuteDataReader(CommandBehavior behavior)
--- End of inner exception stack trace ---
PrestoCommand.ExecuteDataReader(CommandBehavior behavior)
PrestoCommand.ExecuteDbDataReader(CommandBehavior behavior)
PrestoCommand.ExecuteReader()
<PrestoAdo>d__5.MoveNext() line 104
--- End of stack trace from previous location where exception was thrown ---
ExceptionDispatchInfo.Throw()
TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
ThreadOperations.ExecuteWithAbortSafety(Action action)

 

icon

Best answer by Ethem Q 20 November 2023, 23:48

View original

2 replies

Userlevel 5
Badge

This is most likely happening due to you trying to connect to a Trino instance with the driver default settings configured to access a Presto database instead.

Since you are using Trino and not PrestoDB, it will be important to ensure you have adjusted the 'PrestoKind' property to 'Trino'. Find more information on the property here:

https://cdn.cdata.com/help/ORJ/ado/RSBPresto_p_PrestoKind.htm 

Setting the property should resolve the problem. In case you have any other questions or issues feel free to send those over at support@cdata.com or you can always submit a support case here.

Userlevel 3
Badge

Thanks @Ethem Q...that worked!

Reply