Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If i misplace my database file to another folder then i want to change the connection string path. then how to change the connection string at run time.

What I have tried:

I have to put this type of functionality in my desktop application.
Posted
Updated 16-Apr-18 3:28am

This is more than you are asking for, but have a look here: Instance Storage - A Simple Way to Share Configuration Data among Applications[^]
I have a number of apps which connect to the same SQL instance via different databases, and this code lets me change the SQL server connection string in one place and it seamlessly works for all the apps using the code.
 
Share this answer
 
Your app.config file will be renamed to appname.exe.config when built, you can edit this file with a text editor or use methods like:
Properties.Settings.Default.FirstUserSetting = "abc";
More information here: Managing Application Settings (.NET)[^]
 
Share this answer
 
Comments
Member 11776570 19-Apr-18 5:26am    
But i have to change from app.config file. this is not working.
RickZeeland 19-Apr-18 5:55am    
After you have built you application there will not be an app.config file, it will have the application name like this: appname.exe.config.
You can edit this file, if your app is running you will have to restart it for the changes to take effect.
In settings also make sure you select Application and not User settings otherwise your config file will be hard to find ...
Member 11776570 19-Apr-18 8:18am    
Ok. I had done. Problem is solved. ty u for your feedback.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900