Time Out Error in ASP.Net

9.6k Views Asked by At

How can I stop time out error for executing SQL query in ASP.Net? I researched in Google but I couldn't solve my problem correctly.

2

There are 2 best solutions below

1
On

I think your problem is about CommandTimeOut.The time (in seconds) to wait for the command to execute. The default is 30 seconds. Here is full example. Otherwise, you should set the ConnectionTimeOut in your database connection string. Something like that

<add key="ConnString2" value="Provider=SQLOLEDB;User Id=sa;PASSWORD=1;
SERVER=BlurBlur;database=BlurBlur;Connect Timeout=60;"/>

If you use the UpdatePanel, set the AsyncPostBackTimeout.

<asp:ScriptManager ID="ScriptManager1" runat="server" 
AsyncPostBackTimeout ="360000"></asp:ScriptManager>

to be more sure

<httpRuntime executionTimeout="360000"/>
0
On

Please consider you have 2 timeout to deal with when you access database via ADO.net

ConnectionTimeout 

set in connection string: it's the time in seconds asp.net will time out in opening a connection

and

CommandTimeout

es: SqlCommand cmd = new SqlCommand();
cmd.CommandTimeout = .....;

it's the time in seconds the sql command will timeout.

Stefano