Page 304 - DCAP408_WEB_PROGRAMMING
P. 304
Web Programming
Notes 3 Click New and select Custom Connection String from the pop-up menu.
The Custom Connection String dialog box appears.
4. Enter a name for the new connection.
5. Enter the connection string and use the Server.MapPath method to supply the DBQ
parameter.
Example: Suppose the virtual path to your Microsoft Access database is /jsmith/data/
statistics.mdb. The connection string can be expressed as follows if you’re using VBScript as
your scripting language:
Driver={Microsoft Access Driver (*.mdb)};DBQ=” & Server.MapPath(“/jsmith/
data/statistics.mdb”)
There are several ways to define a connection to a database. A DSN Less Connection is defined
by supplying the precise full file path to the physical database:
“DRIVER={Microsoft Access Driver (*.mdb)}; _
DBQ=D:\...\x.mdb;UID=admin;UserCommitSync=Yes; _
Threads=3;SafeTransactions=0;PageTimeout=5; _
MaxScanRows=8;MaxBufferSize=2048; _
Create a DSN-less Database Connection
The easiest way to connect to a database is to use a DSN-less connection. A DSN-less connection
can be used against any Microsoft Access database on your website.
If you have a database called “northwind.mdb” located in a web directory like “c:/webdata/”,
you can connect to the database with the following ASP code:
<%
set conn=Server.CreateObject(“ADODB.Connection”)
conn.Provider=”Microsoft.Jet.OLEDB.4.0"
conn.Open “c:/webdata/northwind.mdb”
%>
Notes Note, from the example above, that you have to specify the Microsoft Access database
driver (Provider) and the physical path to the database on your computer.
Create an ODBC Database Connection
If you have an ODBC database called “northwind” you can connect to the database with the
following ASP code:
<%
set conn=Server.CreateObject(“ADODB.Connection”)
conn.Open “northwind”
%>
298 LOVELY PROFESSIONAL UNIVERSITY