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
%>
  • 6 Users Found This Useful
Was this answer helpful?

Related Articles

Connection Strings

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

How can I manage my SQL 2005 database?

To connect to SQl 2005 databases you need Microsoft SQL Server Management Studio. ...

How can I manage my SQL database without SQL enterprise manager?

We have installed a tool called WebSQL which will allow you to manage your databases through a...

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

How do I reference my SQL database through my code?

How do I reference my SQL database through my code? Please reference your sql server databases...