MySqlException not trapped in try/catch block

"Price, Randall" <[email protected]>
Newsgroups gmane.comp.db.mysql.odbc
Message-ID <[email protected]>
Hello,

 

I have a long running query that generates a MySqlException due to the
query timing out.  It takes about 55 seconds to run on our production
server.  The MySqlException is NOT being trapped in my try/catch block.

 

Here is the error:

 

MySql.Data.MySqlClient.MySqlException was unhandled

  Message="You are not owner of thread 58"

  Source="MySql.Data"

  ErrorCode=-2147467259

  Number=1095

  StackTrace:

       at MySql.Data.MySqlClient.MySqlStream.OpenPacket()

       at MySql.Data.MySqlClient.NativeDriver.ReadResult(UInt64&
affectedRows, Int64& lastInsertId)

       at MySql.Data.MySqlClient.MySqlDataReader.GetResultSet()

       at MySql.Data.MySqlClient.MySqlDataReader.NextResult()

       at
MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior
behavior)

       at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()

       at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()

       at MySql.Data.MySqlClient.MySqlCommand.Cancel()

       at MySql.Data.MySqlClient.MySqlCommand.TimeoutExpired(Object
commandObject)

       at System.Threading._TimerCallback.TimerCallback_Context(Object
state)

       at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)

       at System.Threading._TimerCallback.PerformTimerCallback(Object
state)

 

 

Here is my C# code:

 

try

{

    DateTime datStop  = DateTime.Today;

    DateTime datStart = datStop.AddDays(-29);

 

    strSQL = String.Format("CALL
sp_webReport_Graph_GetUpdatesInstalled_ByDay('{0}', '{1}')",

                           datStart.ToString("yyyy-MM-dd 00:00:01"),

                           datStop.ToString("yyyy-MM-dd 23:59:59"));

 

    objConnection  = new MySqlConnection(m_strConnectionString);

    objCommand     = new MySqlCommand(strSQL, objConnection);

    objCommand.CommandTimeout = 30;         // <== Can increase to 60 to
prevent error.

    objDataAdapter = new MySqlDataAdapter(objCommand);

 

    objConnection.Open();

    objDataAdapter.Fill(objDataSet);        // <== Error occurs here.

}

catch (MySqlException MySqlEx)

{

    string strMessage = MySqlEx.Message;    // <== Why is is not trapped
here??

}

finally

{

    // Close the connection to the database if it is open.

    if (objConnection.State == ConnectionState.Open)
objConnection.Close();

 

    // Clean up MySQL objects.

    objConnection.Dispose();

    objDataAdapter.Dispose();

}

 

 

The error occurs on the line:

 

    objDataAdapter.Fill(objDataSet);

 

If I increase the CommandTimeout to 60 it works without error.

 

My question is why does the MySqlException not get handled in my catch
block?

 

Thanks,

 

Randall Price

Secure Enterprise Technology Initiatives

Microsoft Implementation Group

Virginia Tech Information Technology

1700 Pratt Drive

Blacksburg, VA  24060

Email:      [email protected]

Phone:     (540) 231-4396
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.