Hypertext Links
Image formats
Text Formatting
Forms
Tables
Stylesheets
Databases and ASP
   
ASP Home > | ODBC > | Database Connection

Database Connection

In order to make a database call from the web the first think we need is database connection. The connection string is how ADO (the DB access layer used in ASP) knows how to find your database. There are many ways to connect to the database, here are some sample database connection strings:

Note: ¬ means there is no line break.

OLE DB Method for Access

<%
set cnn = server.createobject("ADODB.Connection")
cnn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;¬
DATA SOURCE=D:\Your_database.mdb"
%>

Where:

- Provider, which is the type of OLE-DB provider
- Driver, to identify the ODBC driver (Open Database conectivity) eg: Access or SQL Server
- DSN, which is name of the data source


DSN Less connection for Access

<%
set cnn = server.createobject("ADODB.Connection")
cnn.open "DRIVER={Microsoft Access Driver (*.mdb)};¬
DBQ=D:\Your_database.mdb"
%>


File DSN Connection Method for Access
<% set cnn = server.createobject("ADODB.Connection")
cnn.open "FILEDSN=AccessDSN"
%>

OLE DB Method for SQL

<%
set cnn = server.createobject("ADODB.Connection")
cnn.open "PROVIDER=SQLOLEDB;DATA¬ SOURCE=sqlservername;UID=username;PWD=password;¬
DATABASE=databasename "
%>