These examples are for demonstration purposes only. You must paste this code in your ASP code to make a connection to the specified database. Note that you must change elements such as database name, server name, database location, dsn, and so on.
Without DSN
<%
Set Cnn = Server.CreateObject("ADODB.Connection")
Cnn.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\websites1\yourdomainname.com\folder\mydatabase.mdb"
%>
OLE DB
<%
Set Cnn = Server.CreateObject("ADODB.Connection")
Cnn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=c:\websites1\yourdomainname.com\folder\mydatabase.mdb"
%>
File DSN
<% Set Cnn = Server.CreateObject("ADODB.Connection")
Cnn.open "FILEDSN=ADSN"
%>
With DSN and no User ID/Password
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "DSNname"
%>
With DSN and User ID/Password
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open "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:\websites1\yourdomainname.com\folder\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("c:\websites1\yourdomainname.com\folder\mydatabase.mdb")
Conn.Open DSNtest
%>
Article ID: 27, Created: May 9, 2008 at 9:10 AM, Modified: August 15, 2017 at 7:08 AM