Solved

Visual Studio 2012 VB.NET - Change SQL connection dynamically

Posted on 2013-06-13
5
346 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:
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 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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

729 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