locked
Time out error in between running: Not frequent RRS feed

  • Question

  • Hi All,

    I am facing serious issue with my App and SQL.

    I am having desktop application, and it executing operation on sql.

    I am facing weird Time out exception in between running of application.

    It is also not frequent, this issue i am facing only once or twice in a month.

    Other days it run just fine.

    Please help me to find the cause and how can i prevent this.

    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, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
       at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
       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, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
       at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
       at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
       at DbEngine.DbConnection.ExecuteCommand(SqlCommand cmd)


    Jiten Patoliya Windows C# developer

    Tuesday, September 8, 2015 10:16 AM

Answers

  • That is a generic error message and in no way helps diagnose the problem. 

    There are many, many, many reasons for the .Net application to report a timeout.  This is not a SQL Server issue, but an application issue.  The default timeout is 30 seconds for the entire completion on a TSQL command from .Net.  If there is blocking or a backup running or a problem on the client side, these can all cause the command to run longer than 30 seconds and cause this error.

    You need to trap the TSQL command running and diagnose the reason for the error message.

    Tuesday, September 8, 2015 12:09 PM

All replies

  • Take a look at this thread. You may have the same problem!
    Tuesday, September 8, 2015 10:41 AM
  • Hello,

    The default command timeout is 30 seconds and it seems, it this case the executed command took longer, e.g. caused by locking. You can increase the timeout value or you have to optimize your statements.


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Tuesday, September 8, 2015 10:50 AM
  • But how to know which statement need optimization.

    Because as i discussed, this is issue is rarely occurring.

    Also on other machines it does not even occurring.


    Here's the method which is called through all execution over db. It has proper lock before execution.

     public static int ExecuteCommand(SqlCommand cmd)
            {
                cmd.Connection = ConnSql;
                if (cmd.Connection != null)
                {
                    cmd.CommandType = CommandType.StoredProcedure;
    
                    lock (lockDb)
                    {
                        if (ConnSql.State == ConnectionState.Closed)
                            ConnSql.Open();
                        return cmd.ExecuteNonQuery();
                    }
                }
                return 0;
            }




    Jiten Patoliya Windows C# developer

    Tuesday, September 8, 2015 11:26 AM
  • That is a generic error message and in no way helps diagnose the problem. 

    There are many, many, many reasons for the .Net application to report a timeout.  This is not a SQL Server issue, but an application issue.  The default timeout is 30 seconds for the entire completion on a TSQL command from .Net.  If there is blocking or a backup running or a problem on the client side, these can all cause the command to run longer than 30 seconds and cause this error.

    You need to trap the TSQL command running and diagnose the reason for the error message.

    Tuesday, September 8, 2015 12:09 PM