Changing Databases in runtime

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
onesimus
Posts: 1
Joined: Thu 10 Apr 2008 20:13
Location: Phoenix, AZ
Contact:

Changing Databases in runtime

Post by onesimus » Thu 10 Apr 2008 20:28

I have been working on this problem for the better part of 3 days. I have an intranet website written in ASP.NET 2.0 (VB). I want to select a database based on the user who logs into the system.

Here is the relevant code...


Private taData As New DataSet1TableAdapters.datatableTableAdapter
...
taData.Connection.Open()
taData.Connection.Database = databaseID
...
newDataSet.Tables(0).Rows.Add(dr) 'dr is a dataRow created using .NewRow on newDataSet.Tables(0) and has been populated elsewhere
taData.Update(newDataSet)

the problem is that it updates the database used when defining the table adapter and dataset.

I am using Visual Studio 2005 and I am using the DataSet designer in Visual Studio.

Please help.

Thank You
:(

Alexey.mdr
Posts: 729
Joined: Thu 13 Dec 2007 10:24

Post by Alexey.mdr » Fri 11 Apr 2008 07:17

Try setting the database property of the connection before you open it.
This should solve the problem.

Code: Select all

Private taData As New DataSet1TableAdapters.datatableTableAdapter 
... 
taData.Connection.Database = databaseID
taData.Connection.Open() 
... 
newDataSet.Tables(0).Rows.Add(dr) 'dr is a dataRow created using .NewRow on newDataSet.Tables(0) and has been populated elsewhere 
taData.Update(newDataSet) 

Post Reply