-1

I am working on a web application that has been build on asp.net technology and there is a stored procedure call on button click event which is taking around 1 min to 2 min execution time, and the page is throw below exception once it pass 30 sec. The code file is missing because application is developed by someone else but i am able to access the web.config file through IIS.

What changes will be needed in web config file to tackle the problem :

below is the error i am getting :

below is the error :

Server Error in '/' Application.

The wait operation timed out Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ComponentModel.Win32Exception: The wait operation timed out

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[Win32Exception (0x80004005): The wait operation timed out]

[SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +388 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +717 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4515 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +61

Rahul Singh
  • 30
  • 1
  • 7
  • If you you have a stored procedure that takes more than a couple seconds to execute, you really shouldn't be calling that in the context of an HTTP request/response. You should run it in a background process. Have a separate application (perhaps a Windows Service using [TopShelf](http://topshelf-project.com/)). Communicate between your web service and the background process using HTTP calls or a message queue. – mason Jan 17 '18 at 17:58
  • thanks for your advice and this is what already in my mind, just looking for solution using web config, please suggest me any method that can be useful with regards to web config changes – Rahul Singh Jan 17 '18 at 18:02
  • It's [not just web.config](https://stackoverflow.com/questions/1198951/how-to-set-the-query-timeout-from-sql-connection-string) that you need to change. The [command timeout is by default 30 seconds](https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout(v=vs.110).aspx). You need to change it if you're going to have long running commands. – mason Jan 17 '18 at 18:07
  • As I have already mention I have access to web config file and stored procedure :( – Rahul Singh Jan 17 '18 at 18:15
  • And as I pointed out, that's not enough. If you don't have access to the source code, then you'll need to figure out who does and request that they fix it. – mason Jan 17 '18 at 18:16
  • Thats the main issue if you have any suggestion without have source code please suggest. – Rahul Singh Jan 18 '18 at 05:41
  • Not only do I not have a suggestion that doesn't involve source code, but I'm explicitly telling you that you need access to the source code to solve it. No amount of asking for answers that don't involve source code is going to help you. – mason Jan 18 '18 at 13:18
  • @mason look my question beforing saying anything ,thanks for the help – Rahul Singh Jan 18 '18 at 13:21
  • I have looked at your question. Again, that doesn't invalidate anything I have said. You will need access to the source code if you want to fix this. If the developer works for you, then ask them to fix it or give you the code. If the developer doesn't work for you, then submit a bug report. As a last resort, you can decompile the application to obtain source code, but that is a difficult concept that's too broad to be described here. – mason Jan 18 '18 at 13:23

1 Answers1

0

Use SqlCommand.CommandTimeout Property

Gets or sets the wait time before terminating the attempt to execute a command and generating an error.

Default Time : The time in seconds to wait for the command to execute. The default is 30 seconds.

Update your ConnectionString in weweb.config some thing like

 "Data Source=**;Initial Catalog=**;Timeout=90;Persist Security Info=True;User ID=**;Password=**"

Read this in cs file like SqlCommand command = new SqlCommand(queryString, connection); command.CommandTimeout = ConfigurationManager.AppSettings["CommandTimeOut"]

or If you want to set directly while Querying

// Setting command timeout to 90 seconds
command.CommandTimeout = 90;
Ehsan Ullah Nazir
  • 1,827
  • 1
  • 14
  • 20