Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Vb.net to sql Server connection

Posted on 2012-03-16
2
Medium Priority
?
220 Views
Last Modified: 2012-03-16
I have a winForms application that is doing tons of reads/writes to a database on hundreds of installed clients.    My question is ->  Is it better to open a connection to the server and keep it open during the session (hours - sometimes days).

(One issue here is that if computer goes to sleep after inactivity SQL will drop the SSID.)

OR

is it beneficial to Open/Close connection on every read/write.   This would be cause some additional overhead.  But, would always ensure that a new connection is established (if server is available).

What is your experience?
0
Comment
Question by:browe68
2 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 2000 total points
ID: 37731087
If you keep it open, you are frustrating the server's ability to manage the connection pool.

SQL Server Connection Pooling (ADO.NET)
http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx

Note the following from the above link:
We strongly recommend that you always close the connection when you are finished using it so that the connection will be returned to the pool. You can do this using either the Close or Dispose methods of the Connection object, or by opening all connections inside a using statement in C#, or a Using statement in Visual Basic. Connections that are not explicitly closed might not be added or returned to the pool. For more information, see using Statement (C# Reference) or How to: Dispose of a System Resource (Visual Basic) for Visual Basic.

Generally it is recommended that you do not keep a connection open longer than needed.
0
 

Author Closing Comment

by:browe68
ID: 37731146
Thanks!
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question