Search the Knowledgebase Browse by Category
      Home       Web Hosting       Web Hosting Guide       Sample Scripts (Windows)
   Connecting to MsSQL using DSN (Windows)

This is one of the most simplest way to get MsSQL database connection.

DSN stands for 'Data Source Name'. It is an easy way to assign useful and easily rememberable names to data sources which may not be limited to databases alone.

<%
'declare the variables
Dim Connection
Dim Recordset
Dim SQL

'declare the SQL statement that will query the database
SQL = "SELECT * FROM TABLE_NAME"

'create an instance of the ADO connection and recordset objects
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")

'open the connection to the database
Connection.Open "DSN=dsn_name;UID=user_name;PWD=password;Database=database_name"

'Open the recordset object executing the SQL statement and return records
Recordset.Open SQL,Connection

'first of all determine whether there are any records
If Recordset.EOF Then
Response.Write("No records returned.")
Else
'if there are records then loop through the fields
Do While NOT Recordset.Eof
Response.write Recordset("FIRST_FIELD_NAME")
Response.write Recordset("SECOND_FIELD_NAME")
Response.write Recordset("THIRD_FIELD_NAME")
Response.write "<br>"
Recordset.MoveNext
Loop
End If

'close the connection and recordset objects to free up resources
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
%>

Live Support

If you have any questions at all, please don't hesitate to contact us

+91.22.28663101, 66789456

To submit Support ticket, click here


     Related FAQs
Setting up feedback form using ASP
Using AspEmail in ASP and ASP.Net
Using CDO (Collaboration Data Objects)
Connecting to MsSQL using DSN (Windows)
Connecting to MsSQL using DSN-less connection (Windows only)
File upload using Asp and Asp.Net
MsSQL Server Connection Strings - ODBC, OLE DB