locked
SqlException Number RRS feed

  • Question

  • Hoping someone can point me in the right direction on something. I'm currently getting an exception with a SqlException.Number = -2 and a SqlException.ErrorCode = -2146232060. According to documentation the SqlException.Number should be in sysmessages, but it isn't.

    I've seen a post saying that the SqlException.Number could correspond to http://msdn2.microsoft.com/en-us/library/ms681381.aspx, but what about a -2? Can anyone confirm this or point me in the right direction?

    Also, where can I find information on the ErrorCode?

     

    Thanks,

    Mike

     

    P.S. Below is the actual exception information as I have it:

    Log Entry : 2:01:11 AM Thursday, July 26, 2007

    clsSQLDatabase RETRY # 0:

    SqlException Properties:

    Class: 11

    ErrorCode: -2146232060

    Errors:

         Error #1

         Class: 11

         LineNumber: 0

         Message: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

         Number: -2

         Procedure:

         Source: .Net SqlClient Data Provider

         State: 0

    HelpLink:

    LineNumber: 0

    Number: -2

    Procedure:

    State: 0

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)

       at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

       at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()

       at System.Data.SqlClient.SqlDataReader.get_MetaData()

       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)

       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)

       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)

       at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)

       at System.Data.SqlClient.SqlCommand.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(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)

       at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)

       at Shared_Database.clsSQLDatabase.Fill(SqlCommand objSqlCommand, DataTable& dtbTable) in C:\Sandbox\New Product ID Database\Shared Database\clsSQLDatabase.vb:line 2212

       --- End of inner exception stack trace ---

       at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)

       at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)

       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

       at System.Delegate.DynamicInvokeImpl(Object[] args)

       at System.Delegate.DynamicInvoke(Object[] args)

       at Shared_Database.clsSQLDatabase.ExecuteWithRetries(Delegate dlgMethod, Boolean booForceReconnect, Object[] objArgs) in C:\Sandbox\New Product ID Database\Shared Database\clsSQLDatabase.vb:line 2140

     

    Thursday, July 26, 2007 7:03 PM

Answers

  • Have you checked EventLog on a server to see if database server does not log any error? I do not believe you will get much of information from timeout exception.

    Wednesday, August 1, 2007 9:48 AM

All replies

  • If you want to rely on error numbers to build logic of your application, then it is not the best way, since error numbers could change. I would suggest catching specific types of exceptions and handling them properly.

     

    Friday, July 27, 2007 3:03 AM
  • I completely agree. The problem is the application is timing out and I'm not sure why. It will throw this exception before the 30 second command timeout.

    I was hoping to find more information in the exception.

     

    Monday, July 30, 2007 12:28 PM
  • When command timeouts, you will not get more information. It just timed out because it did not finish on time and provider will not tell you why. Best way to figure out in this case is to profile your SQL statement and see why it takes so much time to execute. Most likely it is really huge result set or missing indexes.

     

    Tuesday, July 31, 2007 10:15 AM
  • Thanks for the response.

    I have the profile trace and the attention event is sent milliseconds after the query is started and the application receives a Timeout Exception. I'm having a hard time believing that the command is timing out after milliseconds. The query is very simple.

    That's why I was hoping to find more information in the event that it isn't actually a timeout, but a disconnect or something and ADO.NET was just throwing a Timeout for some reason as a default response.

     

    Mike

    Tuesday, July 31, 2007 1:30 PM
  • Have you checked EventLog on a server to see if database server does not log any error? I do not believe you will get much of information from timeout exception.

    Wednesday, August 1, 2007 9:48 AM
  • I realize this is probably out of the scope of this forum/post but...

     

    Actually I do have an entry that corresponds to the time that the application gets this exception, but it's not from SQL Server but the RAID controller.

     

    Code Snippet

    System Event - "The device, \Device\Scsi\dpti2o1, did not respond within the timeout period"

     

    This has happened multiple times during nightly SQL Server backups and has resulted in the exception listed in my original post. The thing that has had me stumped is:

     

    1) How this could result in a Timeout for the application after milliseconds (according to the Profiler Trace) instead of the expected 30 seconds?

    2) If this isn't truly a command timeout, what is it?

     

    I realize my issues go beyond the exception. Really it just came down to the time discrepancy that lead me to looking into the exception, because I found it to be odd.

     

    Thank you very much for your time. I'll take your advice and try and gather more information elsewhere in troubleshooting this problem.

     

     

    Mike

    Wednesday, August 1, 2007 2:31 PM