0

I tried to set ConnectionTimeout of SqlConnection object (C#). But it is read-only property. Default timeout to establish connection is specified as 15 seconds. I want to increase the timeout to 60 seconds.

Is there any other way to set ConnectionTimeout property?

4
  • 1
    The timeout is specified by the connection string used to initialize the SqlConnection object. See the example on msdn.microsoft.com/en-us/library/… Commented Jun 6, 2014 at 5:05
  • Change Timeout Setting in Web Config Commented Jun 6, 2014 at 5:06
  • In web.config replace Connect Timeout=15 with Timeout=60 Commented Jun 6, 2014 at 5:07
  • @Namfuak Actually I referred the link before ask question... I didn't see the example as it was collapsed.. Thanks.. Commented Jun 6, 2014 at 5:28

2 Answers 2

2

You can set the connection timeout in the connection string your pass to the SqlConnection instance.

"Connection Timeout=60"
Sign up to request clarification or add additional context in comments.

Comments

0

if it's for one or two query probs then you can set the CommandTimeout property.

cmd.CommandTimeout = Convert.ToInt16(ConfigurationManager.AppSettings["CommandTimeout"].ToString());

2 Comments

CommandTimeout and ConnectionTimeout are not identical. Take a look at this answer for an explanation of it.
yes that's y I have writen in my answer if one or two query exceution take more time then set the CommandTimeout

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.