Microsoft Access database connection strings

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
%>

Leave a Reply