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

  • Home
  • SEARCH
  • 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 guidance on modelling services and operations in WCF. I have
I have a design issue that I would appreciate some input on. I would
I have an interesting problem and would appreciate your thoughts for the best solution.
I would like to update my SQL lite database with the native update-method of
I'm new to regular expressions and would appreciate your help. I'm trying to put
I've hit a blank here and would appreciate a kick start. I have two
I've been researching memory mapped files for a project and would appreciate any thoughts
My code works (yeah!) which sends json to a server.. would appreciate any thoughts
I would really appreciate any suggestions, no matter how simple or complex, to help
Assuming such a query exists, I would greatly appreciate the help. I'm trying to

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.