Click here to Skip to main content
15,910,886 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have written a connection string to be used in a Windows appliation, to which i need to set connection timeout property. it should be infinte or till the command completes.
here is the code of connection string...

string strCon = "Database=inventory;UserID=root;Password=root;server=localhost;Connection Timeout=900";//60 second * 15 minutes


but its not working. Gives exception ... "Server timed out."
plz help me out.
Posted
Comments
Member 11651318 22-May-17 2:02am    
how can give the max connection time out value in c#

Most accepted method of doing this is through the
CommandTimeout property of the SqlCommand object.
Set it to 0 for an infinite timeout.
For More Information click here.
 
Share this answer
 
v2
Put Connection timeout to 0. A value of 0 indicates no limit (an attempt to execute a command will wait indefinitely).
But do not set connection timeout in connection string. Because an attempt to connect waits indefinitely. So you can use in your command like SqlCommand.CommandTimeout=0;This is the good practice.
 
Share this answer
 
v2
Comments
Member 12181406 12-Aug-16 10:35am    
Do not ever set the timeout to 0. This will suspend the SPID indefinitely. If you cannot connect to the DB and get connected in 15-30 seconds, then there is an issue. Maybe there is too much activity and the pool is exhausted - fix this - do not wait indefinitely - ever.

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