Versions des environnements
SQL Server:
SQL Server 2008
>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.
>
>UPDATE. An idea just occurred to me. What if on every call to the SQL Server I store the time of the call to the application property. Then, every time another call needs to be made, the code would check how much time elapsed since the last call. Then if the time is greater than the set Time Out, create new connection, otherwise, use existing.
>Does it make sense? Is it practical?
My understanding has always been to keep a connection open for the minimum time possible. Execute a query into a local data source, or execute an Update / Insert / Delete, or run a SP, or whatever, and then release the connection. That way you aren't holding on to a connection you no longer need and don't have to worry about unreleased handles. As others have already pointed out, with connection pooling we get the best of both worlds.
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement