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?
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.