how to give connection in web config file?
since we g开发者_开发知识库ive connection in aspx.cs file we want to give connection in web config file .how to give connection.
Do you mean connection string?
If so then what I do is have my web.config file like this;
<connectionStrings configSource="ConnectionStrings.config" />
And then I have a connectionstrings.config file;
<connectionStrings>
<add name="Production" connectionString="Data Source=MYDS; Initial Catalog=InitCat; User ID=UID; Password='Password';"
providerName="System.Data.SqlClient" />
<add name="PreProduction" connectionString="Data Source=MYDS; Initial Catalog=InitCat; User ID=UID; Password='Password';"
providerName="System.Data.SqlClient" />
<add name="Development" connectionString="Data Source=MYDS; Initial Catalog=InitCat; User ID=UID; Password='Password';"
providerName="System.Data.SqlClient" />
</connectionStrings>
Then, based on a flag, I load the relevant connection string using;
System.Configuration.ConfigurationManager.ConnectionStrings["PrePorduction"].ConnectionString
You can use the ConnectionStrings element in the Configuration settings. If you want to know the specific format for different providers and various options that can be specified in the connection string property have a look at connectionstrings.com
精彩评论