none
odbcDataAdapter.Fill is throwing SEH Exception RRS feed

  • Question

  • newOdbcCommand(selectStr, connection.conn);
     OdbcDataAdapter odbcDataAdapter = newOdbcDataAdapter(selectStr, connection.conn);
     DBWrapper.logger.Debug("{0}-- fetched the connection for query -- {1} -- using {2}", Thread.CurrentThread.Name, selectStr, connection.connName);

    // below line is causing SEH Exception

     odbcDataAdapter.Fill(dataSet, "data");

    I am running three threads parallely  each of then uses the above code.

    The code is running for certain amount of time like 7 hours. after some time it is throwing SEH Exception. Please help me with the Issue.

    Stack Trace:- 

     General Exception -- System.Runtime.InteropServices.SEHException: External component has thrown an exception.
       at System.Data.Common.UnsafeNativeMethods.SQLExecDirectW(OdbcStatementHandle StatementHandle, String StatementText, Int32 TextLength)
       at System.Data.Odbc.OdbcStatementHandle.ExecuteDirect(String commandText)
       at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod)
       at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader)
       at System.Data.Odbc.OdbcCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.Odbc.OdbcCommand.ExecuteDbDataReader(CommandBehavior behavior)
       at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
       at InstaGateWayBackend.DBWrapper.SelectDataSet(String selectStr)
    Monday, December 31, 2018 4:51 PM

All replies

  • Did you investigate the details (properties) of SEHException?

    If connection.conn is a OdbcConnection, it is not reliable to use in different threads; this class is not thread-safe according to Documentation. Maybe try creating distinct objects in each thread. Make sure that other shared objects are thread-safe.


    • Edited by Viorel_MVP Monday, December 31, 2018 5:48 PM
    Monday, December 31, 2018 5:46 PM
  • Hi varun22297,

    Thank you for posting here.

    For your question, normally, the oldb would not throw structured exception, I could not reproduce the error. Could you provide a code sample which could reproduce the error for me to test?

    Here is the details about the SEH Exception for your reference.

    https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.sehexception?view=netframework-4.7.2

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 1, 2019 5:31 AM
    Moderator
  • Hi Wendy,

    Thanks for Reply.

    The exception is thrown from odbcDataAdapter.Fill method i am not using oldb.

    Below is the code sample.

                   

    Thread Thread1 = new Thread(new ThreadStart(StartProcess));

    Thread.Start();


    Thread Thread2 = new Thread(new ThreadStart(StartProcess));
    Thread2.Start();

    public static void StartProcess()
            {
                while (true)
                {
                    try
                    {        
                        SelectData();
                    }
                    catch (Exception excp)
                    {
                    }
                }
            }


    public static DataSet SelectData(string Str)
            {

    OdbcCommand cmdStr = new OdbcCommand(Str, cn.conn);
    OdbcDataAdapter da = new OdbcDataAdapter(Str, cn.conn);
    da.Fill(ds, "data");

    }

     


    • Edited by varun22297 Tuesday, January 1, 2019 3:11 PM
    Tuesday, January 1, 2019 3:11 PM
  • Hello,

    If you look at what this exception is 

    he SEHException class handles SEH errors that are thrown from unmanaged code, but that have not been mapped to another .NET Framework exception.

    This leads me to believe that outside of your code perhaps in the core of the ODBC managed data provider the memory may not be handled correctly especially given it's happened many hours (7) later.

    One thing to try is to restart the code after X amount of hours (say every five hours) and see if you get this exception thrown.

    Also, never use a try-catch that has an empty catch, either remove it or deal with the exception or at least log the exception to a file or email it to yourself.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, January 1, 2019 3:27 PM
    Moderator