Chnaging connectionString and reloading it
-
Hey guys, I want to the following, load a specific connection string from app.config change it then re load it in run time. any suggestions THX
mrkeivan wrote:
load a specific connection string from app.config change it then re load it in run time.
Confusing little bit. Try this Connection Strings and Configuration Files [^]
thatraja |Chennai|India|
Brainbench certifications
Down-votes are like kid's kisses don't reject it :-)
Do what you want quickly because the Doomsday on 2012 :-) -
mrkeivan wrote:
load a specific connection string from app.config change it then re load it in run time.
Confusing little bit. Try this Connection Strings and Configuration Files [^]
thatraja |Chennai|India|
Brainbench certifications
Down-votes are like kid's kisses don't reject it :-)
Do what you want quickly because the Doomsday on 2012 :-)Hey, thanx for the quick reply, let me clarify what I posted earlier. I want to retrieve the connectionString I have, make a change to it (change the data source) and load it back in App.config. ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[name]; // If found, return the connection string. if (settings != null) returnValue = settings.ConnectionString; return returnValue; something like this: returnValue = // my new connection string // now load it back and connect to database using the new string in runtime THX
-
Hey, thanx for the quick reply, let me clarify what I posted earlier. I want to retrieve the connectionString I have, make a change to it (change the data source) and load it back in App.config. ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[name]; // If found, return the connection string. if (settings != null) returnValue = settings.ConnectionString; return returnValue; something like this: returnValue = // my new connection string // now load it back and connect to database using the new string in runtime THX
That has nothing to do with "connection strings" though. Read up on using the app.config and Configuration class and the System.Configuration namespace. There is also a newer connection section that Microsoft added. Idea is similar. Also note that writing back to the App.config, as far as I am concerned, means it is no longer human maintainable. It will remove most formatting and all comments.
-
Hey guys, I want to the following, load a specific connection string from app.config change it then re load it in run time. any suggestions THX
add connection string to app.Config file under tag such as
right click on solution explorer second and add reference System.Configuration
string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["connStr1"].ConnectionString;
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connStr);
conn.Open();