Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI all,

I have created one basic software adding data to sql and editing the same .

I have created sql connect with the help of App.config file.

Now I want to give that software exe to client and also the option to change sql path connection string at user level .

if I am crating a setup file how can i change details according to client machine.

please help.

What I have tried:

I tried to create setup but not able to add config file please help
Posted
Updated 28-Feb-19 6:27am

var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);  
var connectionStringsSection = (ConnectionStringsSection)config.GetSection("connectionStrings");  
if(connectionStringsSection != null)  
{  
   connectionStringsSection.ConnectionStrings["aConnectionName"].ConnectionString = "server=Your new connection information";  
   config.Save();  
   ConfigurationManager.RefreshSection("connectionStrings"); 
} 


I assume you will have a way to validate the new connection string before allowing it to be changed.
 
Share this answer
 
 
Share this answer
 
You can find the location of the user config file as follows:
var pathUserConfig = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
If you want the user to be able to edit the settings you can show the file contents in a TextBox.
 
Share this answer
 

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