Solved

Visual Studio 2012 VB.NET - Change SQL connection dynamically

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

18 Experts available now in Live!

Get 1:1 Help Now