LeeLiam
asked on
Changing Connection String dynamically
I am converting a VB6 app to .NET. In VB6, the connection string was set in code. The user could open a different database using an Open Dialog box. After selecting the file, the new path and name was saved for that and all future connections.
I don't know how to handle this change in .NET. I'm setting up data sources for most forms. When I create the data source, the Data Source Configuration Wizard asks for a connection string. Apparently, this gets saved in some configuration file. This would be fine if the database name and path were identical for every user, but I don't want to be forced into this scenario.
How can I give the user a dialog box to select a file and then, each time they launch the program, it will use that for the connection? I seemed to have read the connection string is read only.
Thanks.
I don't know how to handle this change in .NET. I'm setting up data sources for most forms. When I create the data source, the Data Source Configuration Wizard asks for a connection string. Apparently, this gets saved in some configuration file. This would be fine if the database name and path were identical for every user, but I don't want to be forced into this scenario.
How can I give the user a dialog box to select a file and then, each time they launch the program, it will use that for the connection? I seemed to have read the connection string is read only.
Thanks.
ASKER
Thank you. That is an excellent article and it will take me some time to fully digest it.
In the meantime, can I place a line of code like:
Me.TableAdapter.Connection .Connectio nString = OleConn.ConnectionString
before using the table adapter? Will this override the stored connection string?
Thanks.
In the meantime, can I place a line of code like:
Me.TableAdapter.Connection
before using the table adapter? Will this override the stored connection string?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect.
Thanks for your help.
(I assume you meant 'passing'. :) )
Thanks for your help.
(I assume you meant 'passing'. :) )
LOL, it was a typo :)
Glad I could help!
Glad I could help!
You can save that configuration into settings.
http://www.emoreau.com/Entries/Articles/2007/03/AppSettings-revisited.aspx