Solved

Visual Studio 2012 VB.NET - Change SQL connection dynamically

Posted on 2013-06-13
5
320 Views
Last Modified: 2013-12-02
I have an application that is connected to two SQL Server databases, however I dynamically need to change one of the SQL connections to other databases on the fly.  The databases have exactly the same database scheme and are located on the same SQL Server.

It appears that most of the database connections are read-only and can't be changed.  Is it possible to update this?
0
Comment
Question by:Cmitch
  • 3
5 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39243800
why can't you create new SqlConnection object?

Dim SQLConn As SqlConnection = New SqlConnection
SQLConn.ConnectionString = "Data Source=servername;" & _
"Initial Catalog=databasename;" & _
"User ID=username;" & _
"Password=userpassword;"

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39243802
can u post the current connection code u use?
0
 

Author Comment

by:Cmitch
ID: 39243811
I can successfully create an SQLconnection, however how can I assign this to the exist DataSet and associated TableAdapter?
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39243921
u modify the adapter, for example:
theAdapter.Connection.ConnectionString = connectionString;

Open in new window

0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39244324
you cannot change the connection of currently opened objects. If you change your connection, you need to create new objects
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now