Access connection strings examples in ASP

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

Was this answer helpful?

 Print this Article

Also Read

Connection Strings

We're often asked how to create a connection string to a database.  In fact a variety of...

What is the path to my DB folder ?

If you wish to use an access database with your site - you should upload it via FTP to the DB...

How do I Publish my Microsoft SQL server database

In order to publish your database to your hosting package, you need to use the SQL database...

Login Failed using Sql Management Studio

Error:  You receive a 'Login Failed for User 'myusername''  when...

Why can't I connect to the SQL server using Enteprise Manager

SQL Enterprise Manager tries, by default, to connect via Named Pipes. As this cannot run across...