ASP.Net 2.0 SQL Server database connection string

by top54u.com 07 Jul, 2008

In ASP.Net 2.0 SQL Server Database connection string can also be stored separately in a web.config file that allows you to access the connection string anywhere in the Data Access Layer developed in the ASP.Net web application. ConnectionStrings section feature of ASP.Net 2.0 makes it easy to use single web.config file to store the database connection string that enables you to change the database connection at single a place without searching its usage in the complex code of large web applications. System.Data.SqlClient namespace of ASP.Net 2.0 provides the Data Access methods and functions for SQL Server database.

 

Syntax of ASP.Net 2.0 SQL Server Database connection string

 

<connectionStrings>

<add name="sqlConStr"

connectionString="Data Source=.; Initial Catalog=YOUR SQL DATABASE NAME;User ID=YOUR USERNAME;Password=YOUR PASSWORD;"

providerName="System.Data.SqlClient">

</add>

</connectionStrings>



 

Data Source:

You can use the IP address of the web server configured with SQL server or where you have hosted your web site. Mostly in Data Source field localhost is used.

 

Initial Catalog:

Enter the name of the SQL Database.

 

User ID and Password:

Enter the MS SQL Server authenticated username and password.

 

 

Example of SQL Server Database connection string

 

<connectionStrings>

<add name="sqlConStr"

connectionString="Data Source=localhost; Initial Catalog=Northwind;User ID=sa;Password=password;"

providerName="System.Data.SqlClient">

</add>

</connectionStrings>

 

Above example of ASP.Net SQL Server database connection string shows the connectivity with default Northwind database with username "sa" and password "password".

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

10/11/2008 3:43:03 AM




related videos.....
recent posts.....
top54u ezines.....