I'm developing a windows application based on an Access database. I used the wizard to create the table adapters, relations and so on and all works fine.
But using the wizard the connection to the database is hide, the system does the connection by itself. It supposes that the db is stored always in the same location at the same path.
I need to use the application changing as needed the database (same structure different data obviously). My goal is to have a menu item like "Change db" where I can browse the file system and choose the db.
Can I change the connection of the dataset at runtime How can I do
Dado

Change DB connection
JT Snake
Sorry to bore you again...
Dado
Tom Morris
Dado
Tiadd4
My
.Settings.MyConnectionString="BLAH"Where MyConnectionString is the setting name.
Cuzco
davherb
I found a link on the forums:
https://blogs.msdn.com/smartclientdata/archive/2005/07/25/443034.aspx
Basically I had a situation where I wanted to change the connectionstring that M$ store when using the funky project data sources way of coding.
All I did is added this sub to the settings.vb file (instructions how to view the setting code in included in that link above)
Private
Sub MySettings_SettingsLoaded(ByVal sender As Object, ByVal e As System.Configuration.SettingsLoadedEventArgs) Handles Me.SettingsLoaded Me.Item("cnDatabase") = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Me.Item("UserSettingDatabaseLocation") End SubWhere cnDatabase is the name of the Connection you have used for your datasets, and UserSettingDatabaselocation was just a User setting that i have used, but you could set that to anything like your own XML based setting or anything.
Good Luck!
dandoyon
All you need to do is change the connection string of the connection object!
MyCOnnection.ConnectionString="Blah,Blah"
MyDataAdapter.Connection = MyConnection
Amer 570
it my app I see that the my.settings has the connection name in it: cnDBSource
however it is readonly, how do you change it at runtime
Thanks for you help.
Regards,
Michael Proctor