Click here to Skip to main content
13,797,606 members
Rate this:
 
Please Sign up or sign in to vote.
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 16-Apr-18 3:39am
Updated 16-Apr-18 4:28am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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)[^]
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web06 | 2.8.181207.3 | Last Updated 16 Apr 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100