Support Questions

Find answers, ask questions, and share your expertise
Announcements
Check out our newest addition to the community, the Cloudera Data Analytics (CDA) group hub.

Application crash due to exception in ODBC Driver

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

83501-crash2.png

2 REPLIES 2

New Contributor

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.

I have a highly analytical mind and I excel at taking complex ideas and explaining them in accessible language. My writing style is concise and compelling; please take a look at my portfolio and see for yourself.

@Taylor Wilson: I am not sure if I understand what you are looking for. How is your reply related to the question being asked?

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.