1

I have a console application written in C# 4.0. I am running a SQL stored procedure that sometimes takes too long and and a connection timeout exception gets thrown.

To handle it, I first set Timeout to 360 in the connection string in the web.config file but no luck.

Then i tried:

SQLCommand cmd = new SQLCommand();
 cmd.CommandTimeout = 360;

but this is also not working.

Any help would be greatly appreciated. I tried to do same with the Entity Framework 4.0 but had the same issue. The timeout value i am providing is not being applied!

<add name="ConnectionString" connectionString="SERVER=db.mydomain.com;DATABASE=DatabaseName;UID=userID;PWD=Password;Connect Timeout=360;Packet Size=8192;Pooling=True;Min Pool Size=1;Max Pool Size=1000;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />

Exception:

Timeout expired: The timeout period elapsed prior to completion of the operation or the server is not responding.
4
  • So, you want a 6-minute timeout, and it's still timing out at the default 30 seconds? Commented Jun 24, 2012 at 4:04
  • I think you are getting confused with command.CommandTimeout and connection timeout. In your web config u have specified connect timeout to 360 Commented Jun 24, 2012 at 4:17
  • @praveen I see what you are trying to tell me. I am trying both I have added my exception message on top , please take a look Commented Jun 24, 2012 at 4:20
  • 1
    Try removing connection timeout from your web.config file and use only CommandTimeout in your code Commented Jun 24, 2012 at 4:28

2 Answers 2

4

Set the CommandTimeout = 0 in your code and remove it from the config file.

Setting the Timeout = 0 means, it will complete the job in case of long operation also.

Sign up to request clarification or add additional context in comments.

Comments

0

Do you have context connection=true in the connection string in your Web.config file? According to MSDN:

CommandTimeout has no effect when the command is executed against a context connection

2 Comments

I have added my coonectionstring, please take a look
Your connection string looks fine to me so that can't be the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.