Setting up connection string in ASP.NET to SQL SERVER

Ray picture Ray · Apr 13, 2011 · Viewed 684.2k times · Source

I'm trying to set up a connecting string in my web.config file (Visual Studio 2008/ASP.NET 3.5) to a local server (SQL server 2008).

In my web.config, how and where do I place the connection string?

Here's what web.config file looks like right now: http://imwired.net/aspnet/Online_web.config

Answer

Aristos picture Aristos · Apr 13, 2011

You can also use this, it's simpler. The only thing you need to set is "YourDataBaseName".

  <connectionStrings>
    <add name="ConnStringDb1" connectionString="Data Source=localhost;Initial Catalog=YourDataBaseName;Integrated Security=True;" providerName="System.Data.SqlClient" />
  </connectionStrings>

Where to place the connection string

<?xml version='1.0' encoding='utf-8'?>  
  <configuration>  
    <connectionStrings>  
      <clear />  
      <add name="Name"   
       providerName="System.Data.ProviderName"   
       connectionString="Valid Connection String;" />  
    </connectionStrings>  
  </configuration>