Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Visual Studio 2012 VB.NET - Change SQL connection dynamically

Posted on 2013-06-13
5
Medium Priority
?
365 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 42

Accepted Solution

by:
Meir Rivkin earned 2000 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:Meir Rivkin
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:Meir Rivkin
ID: 39243921
u modify the adapter, for example:
theAdapter.Connection.ConnectionString = connectionString;

Open in new window

0
 
LVL 70

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

650 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