0

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 string 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>

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.