Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3630592
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:17:23+00:00 2026-05-19T00:17:23+00:00

I would appreciate some advice on the best method of managing multiple SQL connections

  • 0

I would appreciate some advice on the best method of managing multiple SQL connections .net (VB)

My application connects to four instances of SQL Server (2000, 2005, 2008, 2008R2) restoring databases, modifying data and taking backups.

In addition to managing databases the app also has its own DB (on the 2008 instance) for storing various data.

I’m using two methods to connect to the instances, SMO (For backups, restoring and retrieving information about the databases, size etc) and SqlClient for querying each database for many tasks such as updating fields and executing sql scripts.I have multiple forms for performing various tasks so there are many places I’m opening\closing connections.

Would it be best to maintain a persistent global connection to each instance from the application? (Two in total, one for SMO and the other for SqlClient) or open close a connection for each task I’m performing?) I’m not using LINK as I need the tasks to be as fast as possible.

The connection string will differ on each connection (Based on Instance and Database being connected to) how would I manage this? A string in the config file for the applications database would make sense, as that would be static but the databases being worked on will vary with each connection.

Currently I’m creating a connection for each instance within the main form:

Dim 2000Connection = New SqlConnection("Data Source=" & SQLServerName & _
"\SQL2000;Initial Catalog=Master;User ID=sa;Password=P@ssw0rd;Pooling=True;")

Dim 2005Connection = New SqlConnection("Data Source=" & SQLServerName & _
"\SQL2005;Initial Catalog=Master;User ID=sa;Password=P@ssw0rd;Pooling=True;")

Dim 2008Connection = New SqlConnection("Data Source=" & SQLServerName & _
"\SQL2008;Initial Catalog=Master;User ID=sa;Password=P@ssw0rd;Pooling=True;")

etc

Then using “USE [” & DatabaseName & “]…” to change to the required database to saving creating a new connection string.

I’m using this Class to connect:

Public Class ClassDatabaseConnection
Private Shared connection As SqlClient.SqlConnection

Public Shared ReadOnly Property Instance As SqlClient.SqlConnection
    Get
        If connection Is Nothing Then
            connection = New SqlConnection("Static Connection String;")
        End If
        Return connection
    End Get
End Property

Public Shared Customconnection As SqlClient.SqlConnection
Public Shared Property CustomInstance(Optional ByVal Server As String = "", Optional ByVal Database As String = "Master") As SqlClient.SqlConnection
    Get
        If Customconnection Is Nothing Then
            Customconnection = New SqlConnection("Data Source=" & Server & ";User ID=sa;Password=P@ssw0rd;")
        End If
        Return Customconnection
    End Get
    Set(ByVal value As SqlClient.SqlConnection)
    End Set
End Property
End Class
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:17:24+00:00Added an answer on May 19, 2026 at 12:17 am

    My recommendation would be as follows.

    1. Setup each of the connection strings in the application configuration file, but without pointing to a specific database.
    2. Instantiate and open/close connections as needed, the connection pooling will allow the connections to be reused when possible

    This way has a few key benefits.

    1. It is easy to maintain/update the connections if you need to
    2. You utilize connection pooling and the underlying system to manage the connections and focus on opening/closing your connection as needed to prevent resource leaks and/or code that is hard to debug

    You can continue to then use your various SQL statements to switch between the individual databases being used with your SQL statements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would appreciate some advice on best practices with my first WPF app (a
In the following example, I would appreciate some feedback on the best method for
I would appreciate some help on creating the proper SQL to retrieve only one
I would appreciate some ideas and advice to help reconcile my model design with
I would appreciate some advice on how to structure a database for the following
I am working on a comment system in Codeigniter and would appreciate some advice
I would like some advice on the best approach for transferring DB data from
I would appreciate some help with something I working on and have not done
I would appreciate some help with an UPDATE statement. I want to update tblOrderHead
I have a problem finding references to this subject and would appreciate some help.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.