About the value of appSettings in the Web.config file
Hi, I'm trying to run a website locally. The website was running on the server, and I got a local copy of everything,including the database. I'm now facing the issue of changing the connection string in the Web.config file.could anyone tell what I shoud put in for the server name? I tried "Local" but didn't get good luck. Any help is highly apprecitated. Thanks in advance!
<
configuration><system.web><compilationdefaultLanguage="c#"/><identityimpersonate="true"/><authenticationmode="Windows"/><pagesvalidateRequest="false"/></system.web><appSettings><addkey="CompanyConnectionString"value="SERVER=DBDEVELOP\QA,7842;Database=friday_dev; uid=user;pwd=12345;"/></appSettings></
configuration>
As an example this minimal web.config with an appSetting entry to hold our connection string:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation defaultLanguage="c#" debug="true" />
</system.web>
<appSettings>
<add key="ConnectionInfo" value="server=(local);database=Northwind;Integrated Security=SSPI" />
</appSettings>
</configuration>
To read the key you use the ConfigurationSettings class from the System.Configuration namespace:
private void Page_Load(object sender, EventArgs e)
{
string connectionInfo = ConfigurationSettings.AppSettings["ConnectionInfo"];
using(SqlConnection connection = new SqlConnection(connectionInfo))
{
connection.Open();
// perform work with connection
}
}
You can refer server address by your computer name also! Got it ?