开发者

connection string issue in web.config of ASP.Net

I am using VSTS 2010 + C# + .Net 4.0 to develop an ASP.Net application using SQL Server 2008 Enterprise as database. I am learning someone else's code. I notice code like this, I am not sure whether the usage is correct and so I come here to ask for advice.

In the code, I see some code like this, I want to know whether using such method to read connection string from web.config is correct?

ConfigurationManager.ConnectionStrings["DBConnectinString"].ConnectionString

and such code is used to read connection str开发者_StackOverflowing from web.config like below, please notice that connection string is defined outside of system.web section.

<?xml version="1.0"?>
<configuration>
  <configSections>
       <!--this section is empty-->
  </configSections>
  <appSettings>
    ...... content of appSettings
  </appSettings>
  <connectionStrings>
    <add name="DBConnectinString" connectionString="data Source=.;uid=foo;pwd=foo;database=FOODB" providerName="System.Data.SqlClient"/>
  </connectionStrings>
<system.web>
... ... content of system.web
</system.web>
</configuration>


That is the standard place to define connection strings in web.config, yes.

See this for more info: http://msdn.microsoft.com/en-us/library/ms178411.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜