Created on 08-01-2018 05:10 PM - edited 09-16-2022 06:32 AM
We are using Hortonworks ODBC driver to connect hive from C# application.
Here is a sample code to fire query on Hive.
static void Main(string[] args) { string connectionString = "DSN=AzureHDP"; string query = "SELECT * FROM schema_5218.demandquantity"; int queryTimeout = 100; try { using (var connection = new OdbcConnection(connectionString)) { Console.WriteLine("Opening Hive connection."); connection.Open(); using (var cmd = connection.CreateCommand()) { cmd.CommandTimeout = queryTimeout; cmd.CommandText = query; Console.WriteLine("Executing Hive query."); cmd.ExecuteNonQuery(); Console.WriteLine("Hive query executed successfully."); Console.ReadKey(false); } } } catch (Exception e) { Console.WriteLine($"Encountered error during Hive query execution. [{e.Message}]"); Console.ReadKey(false); throw; } }
Issue is that if the network connection drops after the query has been fired on Hive(before query returns) the resulting exception results in application crash.
Reason is that AccessViolcationException is thrown which are not sent to application catch block. So this exception becomes an un-handled exception causing the application to crash.
Is this due to any bug in the ODBC driver? Is there any workaround or fix awaited?
There are certain settings which can be done to catch such exception but those are not recommended by Microsoft. Due this this reason I am not very keep to use these settings. Those settings are [HandleProcessCorruptedStateExceptions] & [SecurityCritical] and legacyCorruptedStateExceptionsPolicy.
Attaching actual application code screenshot. You can that the exception is thrown at the close of the connection using clause and the control does not go to the catch block.
Hortonworks Driver Version: 2.01.10.1014
.Net Version: 4.7
C# version: 7.3
Created 08-03-2018 11:46 AM
Hello I have to make C# application for my website Custom Essay Writing Company is it a good idea? I need some expert suggestion for C# application.
Created 08-05-2018 07:05 AM
@Taylor Wilson: I am not sure if I understand what you are looking for. How is your reply related to the question being asked?