Codefixer - ASP tutorials, resources and software
asp.netPRO “Best ASP.NET Host” – DiscountASP.NET
Home   Articles   Resources   ASP directory   ASP Tutorials   Code Snippets   ASP Applications   Forum
Monday 12 May
MembersPro PayPal - ASP Membership software

ASP.NET 3.5 Hosting – DiscountASP.NET


ASP Partner ASP Partner ASP Partner more partners...

Connecting to an Access database using a Connection String

For our examples on this site we have chosen to use OLEBD rather than ODBC connection strings as they are faster and more stable.

Below are 4 connection strings that you could use 2 OLEBD and 2 ODBC. One example for each provides the physical path of the database and the other uses the Server.MapPath function. We also use the ADO connection in our examples below to open the connection object and make an active connection.

ODBC connection strings

If you know the physical path to your database you can use the code below.

<%
sConnString= "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=c:\myFolderName\myDatabase.mdb"
Set connection = Server.CreateObject("ADODB.Connection")
connection.Open sConnString
%>

If aren't sure about the physical path to your database you can use the Server.MapPath Function which will map the path from the webserver's root folder to your database.

<%
sConnString= "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & Server.MapPath("/myFolderName/myDatabase.mdb")
Set connection = Server.CreateObject("ADODB.Connection")
connection.Open sConnString
%>

OLEDB connection strings

If you know the physical path to your database you can use the code below.

<%
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\myFolderName\myDatabase.mdb"
Set connection = Server.CreateObject("ADODB.Connection")
connection.Open sConnString
%>

If aren't sure about the physical path to your database you can use the Server.MapPath Function which will map the path from the webserver's root folder to your database.

<%
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("/myFolderName/myDatabase.mdb")
Set connection = Server.CreateObject("ADODB.Connection")
connection.Open sConnString
%>


Previous: Connecting to a database without a DSN
LinksPro - Directory  and Link  Management Software




ASP.NET 3.5/2.0 Web Hosting: 3 Months FREE – Click Here!




About | Contact | Advertise | Feedback | Hire Us | Link

Site developed by Michael Wall - Web Design Belfast N.Ireland.
Copyright © 2000-2008. All rights reserved.

Do you intend to move to ASP.NET or have you already?
Yes will do
Have done
ASP does fine
Not a priority


Directory Software