Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Do you check connection on every call to SQL?
Message
From
06/03/2012 06:34:18
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01537347
Message ID:
01537364
Views:
61
>Hi,
>
>My application creates one SQL Server connection at the top of the application and then relies on it for all calls to SQL Server. But I understand that the connection can time out. Therefore, do you recommend that the program checks if the connection is still valid (by e.g. by SELECT CAST(1 as BIT) or some other way) every time the program needs to connect (to SQL Select or Update)? TIA.

See: http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx

When you close a connection in code you will just be returning it to the pool. Likewise, when you open, you will usually be getting an existing connection from the pool.
Given the above it is usually best practice to keep a connection open in code for the minimum possible time - ideally wrap it in a using....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform