Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have query that take from 30 second to 40 second on sql server to return data
where i try to call from my page
it give me that error

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

As you are probably using a SqlCommand for calling the query, you can specify the timeout for that one:

C#
using (SqlConnection cn = new SqlConnection(Configuration.DefaultConnectionString))
{
    using (SqlCommand cmd = new SqlCommand(query, cn))
    {
        cmd.CommandTimeout = 60;
        cn.Open();
        ...


Or specify the timeout for the connection in the web.config (which I will not recommend).

More info here http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout(v=vs.110).aspx[^]


Cheers
 
Share this answer
 
You can set the Connection Timeout=value(may be in sec or millisec can't remember) in connection string for the long running query to achieve this
best of luck.....
 
Share this answer
 
If you give cmd.CommandTimeOut = 0 .Your client API will never time out form SQLSERVER.It will last until the operation is got over.
 
Share this answer
 
Comments
Ajith K Gatty 4-Jun-14 9:30am    
Hi Rajesh,

Do you really think setting that value to 0 and running forever sql server is a good idea??? I dont yhink so.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900