Knowledgebase
Access connection strings examples in ASP
Posted by Phil Parry on 13 October 2007 12:43 PM

With DSN and no User ID/Password

<% Set connectionToDatabase=Server.CreateObject("ADODB.Connection")
connectionToDatabase.ConnectionTimeout=60
connectionToDatabase.Open"DSN=DSNname" %>


VERY IMPORTANT! Make sure to insert the following line where you want to
close the connection]


<% connectionToDatabase.Close
Set connectionToDatabase=Nothing %>


Without DSN (recommended Access connection string)

<%
Set Cnn = Server.CreateObject("ADODB.Connection")
Cnn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\domains\yourdomaincom\db\mydatabase.mdb"
%>


OLE DB

<%
Set Cnn = Server.CreateObject("ADODB.Connection")
Cnn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=C:\domains\yourdomaincom\db\mydatabase.mdb"
%>


File DSN

<% Set Cnn = Server.CreateObject("ADODB.Connection")
Cnn.open "FILEDSN=DSNname"
%>


Another Example of With DSN and no User ID/Password

<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "DSN=DSNname"
%>


With DSN and User ID/Password (NOTE: a user/pass is NOT needed, just optional)

<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "DSN=DSNname","username","password"
%>


Without DSN, using a physical path as a reference

<%
Set Conn = Server.CreateObject("ADODB.Connection")
DSNtest="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtest=dsntest & "DBQ=C:\domains\yourdomaincom\db\mydatabase.mdb"
Conn.Open DSNtest
%>


Without DSN, using Server.MapPath

<%
Set Conn = Server.CreateObject("ADODB.Connection")
DSNtest="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtest=dsntest & "DBQ=" & Server.MapPath("../db/mydatabase.mdb")
Conn.Open DSNtest
%>

(1204 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please enter the text you see in the image into the textbox below (we use this to prevent automated submissions).