changing a connection string run time

B

BillE

I have defined connection strings in the settings tab of the properties page
of a Windows forms project.

Users need to be able to modify the connection string through the
application - how do I change a connection string in the settings
dynamically at run time?

Thanks
Bill
 
J

Jeff Johnson

I have defined connection strings in the settings tab of the properties
page of a Windows forms project.

Users need to be able to modify the connection string through the
application - how do I change a connection string in the settings
dynamically at run time?

Personally I store my connection strings as plain strings. If I need to
fiddle with them I parse them into name/value pairs and change values, then
join them back together.
 
A

Ashutosh Bhawasinka

If just picking up the connection string's text is the issue, you can
create a texbox and take the value form it...

If persisting user supplied connection string is what you need then you
need to have an application setting with scope set to User (not
application). Store the connection string there. Use this value at run
time. You can update this value also when the user specifies their
custom connection string. You may also consider using the Property
Binding feature.

Thanks & Regards,
Ashutosh
 
A

Ashutosh Bhawasinka

Actually, you should always store your connection string in
connectionStrings section of your configuration file.
 
B

BillE

I am surprised that connection strings can't be changed (preserving the
changes) at runtime.

It seems like the connection string will normally have to be changed when an
application is distributed.
 
B

BillE

I DID store the connection string in the "connectionStrings section of your
configuration file"!

What I'm trying to find out is how a user can change and retain a connection
string at run time.

If anybody knows, I would appreciate help with this.

Thanks
 
A

Ashutosh Bhawasinka

Thats the reason it's stored in the <app>.config file. This file is
stored in the same folder as your application/exe file. This is the
standard way to do these kind of things.

If you don't want the user to handle the config file, even then store it
in the config file but provide an UI to view and change it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top