Question Changing data connectstring runtime

TommyLiu

Member
Joined
Jul 29, 2008
Messages
7
Programming Experience
5-10
Dear all,

I have a problem that is when I use the vb 2008 express to connect ms access database by using builtin data source, I cannot change the data source in runtime. For example: I use c:\data\peter.mdb in design time for database design. Then, I use c:\server\david.mdb in runtime.

How can I change it during runtime? Thank you.
 
The connectionstring is stored in the XML configuration file that accompanies the app e.g. MyApp.config

Edit it in there
 
Note, if you must change it on the fly during runtime you have a number of options available:

Either open the settings file and, for the ConnectionString item, change the scope to User Scope and the type to String
Or
Open the code behind the settings file and provide a WriteOnly property or method that will allow you to alter the connection string in your code.

Of the two, I prefer the latter. You can search these forums for "changing connection string runtime" for more results and discussion of the two routes
 
Back
Top