Tuesday, January 18, 2011

ASP.NET VS SQL SERVER CONNECTING STRING

ASP.NET VS SQL SERVER CONNECTING STRING



How To Describe Connection to SQL Server
We will use the System.Data.SqlClient and the System.Data namespaces of ADO.NET. The System.Data contains basic enumerations and classes, which we will use below. The System.Data.SqlClient provides data access to SQL servers such as MS SQL Server 2000 and higher. Add the next snippet to the beginning of your code page in order to get easy access to their classes:

using System.Data;
using System.Data.SqlClient;

To begin "communications" with our server we should define the SqlConnection class, initialize a new instance and set its connection string parameters. There is an example of a connection string below:

string Connection = "server=ALDAN; uid=sa; pwd=sa; database=GAZCAD; Connect Timeout=10000";

Let's understand what each parameter means:

Keyword Description
server > The address of a SQL Server. If the server is on a same computer, where your website runs, define it as "local". If the server is remote, define it as an IP รข€“ address, a domain name or a netbios name (as in the example string) of the server.
Uid> The login name, which is defined at your SQL Server to get access. Our login name is "sa".
Pwd >The password, which is defined at your SQL Server to get access. Our password is "sa".
Database >The database's name, which you connect to. Our database name is "GAZCAD".
Connect timeout> The time in milliseconds. When this time is over and the connection is not established, the timeout exception is thrown. This keyword is not necessary. In our case it equals 10,000 ms. Use so large timeouts when you request a lot of data from the server.