Connection String For ASP And ASP.NET Using SQL Server 2000


When we are start with programming in any language at that time we need to perform many basic tasks, one of them is connecting our application with database and for that we need to set one connection string which is the only way by which we can perform required operation on our database. If you are looking to add, update or delete data or you want to generate different output from your database using your application at that time first of all you have to set one connection string which can communicate with your database. Connection string is like bridge between your application and database. Without defining connection string you can not perform a single operation on your database.

Generally, most of novice programmer are facing problem on how to define connection string in their application so that they can communicate with their database to fulfill their desired task, to overcome this problem I will explain you how to define connection string in your application so that you can connect with database. But before moving further first of all notes that there are two ways of defining connection string in an application. One is using DSN which is called connection string using DSN and second one is without DSN which is called DSNLESS connection string. Here I will explain different connection string used in different languages and platforms.

Connection String used in ASP fro SQL SERVER 2000


Below given is code to connect your database with application

Objcon = server.CreateObject("ADODB.Connection")
dim constr1
constr1=“PROVIDER=SQLOLEDB;server=servername/serverIP;database=databasename;uid=username of database;pwd=password of database;"
objcon.open constr1
Set rs = Server.CreateObject ("Adodb.RecordSet")
rs.ActiveConnection=constr1
rs.LockType=3
rs.CursorLocation=3
rs.CursorType =2
query="select * from table"
rs.open query

Connection string used in ASP.NET for SQL SERVER 2000


Below given is code to connect your database with application
To connect your database with SQL SERVER 2000 you have to import below mentioned namespace
Imports System.Data.SqlClient
Use below given coding to connect with database
dim SQLConn As SqlConnection
dim command As SqlClient.SqlCommand
dim reader as SqlClient.SqlDataReader
SQLConn = New SqlConnection("Data Source=servername/serverip;Network Library=DBMSSOCN;InitialCatalog=databasename;UserID=username of database;Password=password of database;")
SQLConn.Open()
query1 = "select * from table"
Dim com As New SqlClient.SqlCommand(query1, SQLConn)
reader = com.ExecuteReader()
reader.Read()
SQLConn.Close() 

You can just place this connection string to connect to MSSQL Server from ASP.NET page.

(Posted By Aden)

Sign up for a newsletter