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.
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
%>
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 |
Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.
Get your best asp web hosting provider now and save 25%