DSN-Less Database Connection

This section contains the codes and resources related to Classic ASP and ASP.net languages.

DSN-Less Database Connection

Postby MT Shahzad on March 21st, 2008, 7:46 pm

How to connect to a database via a DSN-Less connection

First we instantiate the Connection Object:
Code: Select all
Set Conn = Server.CreateObject("ADODB.Connection")

Next we define the actual connection string:
Code: Select all
sConnString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("db\dbname.mdb") & ";"

Make sure the above line of code is all on one line in your code, don't wrap it. In this statement we are telling ADO (Active Data Objects) that we want to use the MS Access driver and where our database is physically located.

Code: Select all
Conn.Open(MyConnStr)

This is the line of code that actually opens the connection to the database. After you have done this you are ready to execute a SQL statement.
Code: Select all
sql = "select * from myTable"
Set RS = Conn.Execute(sql)
MT Shahzad
Web/Software Developer
http://mts.sw3solutions.com
User avatar
MT Shahzad
Site Admin
 
Posts: 300
Joined: February 29th, 2008, 8:11 am
Location: Muridke, Pakistan

Return to ASP / ASP.net

Who is online

Users browsing this forum: No registered users and 0 guests