Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dear sir


i have an app.config file and i want the user give the database name etc and use the following code but it does not save in config file.

C#
var miconex = new SqlConnectionStringBuilder();
     miconex.DataSource = "SQL-PC"; miconex.InitialCatalog = "control";
     miconex.UserID = "sa"; miconex.Password = "xxxx";

     string saleconfritas = miconex.ToString();
     MessageBox.Show(saleconfritas);
         System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
         string modif = string.Format(ConfigurationManager.ConnectionStrings["con"].ConnectionString,saleconfritas) ;
         config.Save(ConfigurationSaveMode.Minimal);


my app.config file is

XML
<configuration>
	<connectionstrings>
		<add name="con" providername="System.Data.sqlclient" connectionstring="<br mode=" hold=" />			 " />
	</connectionstrings>
</configuration>


When i run the code and check it still shows same as it is.
Posted
Updated 16-Jan-14 18:51pm
v2
Comments
Ron Beyer 17-Jan-14 0:52am    
Can you tell us what directory the executable is stored in? If its the Program Files directory you may not have permission to write to the file. Typically for user settings you want to create a Settings file and it gets stored in the user profile.

XML
<configuration>
    <connectionStrings>
        <add name="Test" connectionString="Data Source=.;Initial Catalog=MyDBTest;IntegratedSecurity=True" providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>





C#
var connection =
    System.Configuration.ConfigurationManager.ConnectionStrings["Test"];
 
Share this answer
 
 
Share this answer
 
Comments
rajbir singh thind 17-Jan-14 1:34am    
but sir it does not show in app.config file and when i run the software after closing it .it again shows null in app.config file. i have to connect again
Sandeep Singh Shekhawat 17-Jan-14 1:41am    
did you debug your code and check it write or not in web.config file. your file should not be readonly.

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