Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Do you check connection on every call to SQL?
Message
 
 
À
06/03/2012 07:13:32
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01537347
Message ID:
01537369
Vues:
32
>>>>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....
>>
>>Does every SQL Server maintains this "connection pool"? Also, what about the fact that the application will slow down if it has to make connection frequently. I notice that when my application makes the first connection it takes a couple of few seconds. If this will be occurring repeatedly I don't think my customers will be happy.
>>Thank you for your input.
>
>It''s not a SQL Server thing - it's ADO.NET functionality. The link I provided explains in detail how this works.
>
>The *very first time* you open the connection you will incur the overhead of 'physically' connecting to the server. But closing the connection does not physically close it - it is just returned to the pool. Next time you ask for the same connection you will probably get the already opened connection from the pool - therefore no noticeable overhead.....

Thank you for the explanation. I didn't look in the link but will do that.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform