Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
Subject: mysql openssl Question
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
Update one field with more fields from another table
Subject: Getting Identity after INSERT
ERROR 2002: Can 't connect to local MySQL server through socket
mysql test 4 1 fails with the gis test
Subject: MySQL Cluster Software
Downgrade Mysql from 4 to 3 23
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Can 't access mysql after kernel upgrade
Executing MySQL Commands From Within C Program
Comparing and writing out BLOBS
Subject: Re: Preventing Duplicate Entries
FULLTEXT query format question
Strange behavior, Table Level Permission
Does the binary log enabling affect the MySQL performances?
mysql:it 's a db not a dbms how it 's possible?!
mysql have same function mthod as Oracle decode()
 
MySqlException not trapped in try/catch block

MySqlException not trapped in try/catch block

2007-05-29       - By Price, Randall

 Back
Reply:     1     2  

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:      Randall.Price@(protected)

Phone:     (540) 231-4396