Link to home
Start Free TrialLog in
Avatar of LeeLiam
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.
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Hi,
 You can save that configuration into settings.
http://www.emoreau.com/Entries/Articles/2007/03/AppSettings-revisited.aspx 
Avatar of LeeLiam
LeeLiam

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.ConnectionString = OleConn.ConnectionString

before using the table adapter? Will this override the stored connection string?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LeeLiam

ASKER

Perfect.

Thanks for your help.

(I assume you meant 'passing'. :) )
LOL, it was a typo :)
Glad I could help!