troubleshooting Question

Should I have one Global or multiple Module level SQL Connection objects?

Avatar of Declan Basile
Declan BasileFlag for United States of America asked on
Microsoft SQL ServerVisual Basic.NETSQL
4 Comments1 Solution35 ViewsLast Modified:
I'm writing a vb.net application that connects to a SQL Server database.  Should a create one SQL Connection object at the main form's class level, assign it a connection string and open it in the load of the main form, keep the connection open for the duration of the program and use it whenever there's a SQL Command object in any of the modules that needs an open SQL Connection object?  Or should I only have module level SQL Connection objects, and every time there's a command object in a module that needs a SQL connection object I would declare a local SQL connection object (local to the module), assign it the connection string, and open it specifically for SQL commands in that module?  In the first approach there will always be a connection the SQL Server even when the program is idle and there doesn't need to be a connection; however, in the second approach the program would have to keep instantiating, assigning a connection string, opening and closing a SQL connection every single time it needs one.  Which is better?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros