开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜