Академический Документы
Профессиональный Документы
Культура Документы
When running Microsoft Jet in an IIS environment, it is recommended that you use
the native Jet OLE DB Provider in place of the Microsoft Access ODBC driver. The
Microsoft Access ODBC driver (Jet ODBC driver) can have stability issues due to the
version of Visual Basic for Applications that is invoked because the version is not
thread safe. As a result, when multiple concurrent users make requests of a
Microsoft Access database, unpredictable results may occur. The native Jet OLE DB
Provider includes fixes and enhancements for stability, performance, and thread
pooling (including calling a thread-safe version of Visual Basic for Applications).
Now that you've picked which database method you will be using, here is a
list of possible connection strings, based on whether you are using Microsoft Access or SQL Server and
OLEDB or ODBC:
SQL Server
ODBC:
• Standard Security:
"Driver={SQL Server};Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;"
• Trusted connection:
"Driver={SQL Server};Server=Aron1;Database=pubs;Trusted_Connection=yes;"
1
OLEDB:
• Standard Security:
"Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;")
• Trusted Connection:
"Provider=sqloledb;Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;"
(use serverName\instanceName as Data Source to use a specific SQLServer instance, only
SQLServer2000)
Access:
ODBC
• Standard Security:
"Driver={Microsoft Access
Driver(*.mdb)};Dbq=\somepath\mydb.mdb;Uid=Admin;Pwd=asdasd;"
• Workgroup:
"Driver={Microsoft Access Driver
*.mdb)};Dbq=\somepath\mydb.mdb;SystemDB=\somepath\mydb.mdw;","admin",""
OLEDB
• Standard security:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;User
Id=admin;Password=asdasd;"
2
Making Database Connections
Opening a connection to a database is a fairly simple process: first, you create a connection
object, then you open the object using either a DSN or specified drivers and path. The latter is
called a DSNless connection, as it requires no system DSN to be set in the server's ODBC applet
in the Control Panel. If you'd like information on setting up a system DSN, be sure to see Setting
A System DSN, or if you prefer a more visual approach, check out ASPKicker's ODBC
Configuration Page.
MS Access
With DSN and no User ID/Password:
<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "DSNname"
%>
DSNless
Using Server.MapPath, which is the path from the webserver root (by default, c:\inetpub\wwwroot)
<%
Set conn = Server.CreateObject("ADODB.Connection")
DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtemp=dsntemp & "DBQ=" & Server.MapPath("/database/casino.mdb")
conn.Open DSNtemp
%>
MS SQL Server
With DSN
<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "DSN=MyDSN;UID=user;PWD=password;DATABASE=databasename"
%>
3
SQL Server: DSNLess
<%
Set conn = Server.CreateObject("ADODB.Connection")
DSNtemp="DRIVER={SQL
Server};SERVER=ServerName;UID=USER;PWD=password;DATABASE=databasename"
conn.open DSNtemp
%>
FoxPro: DSNLess
<%
Set Conn = Server.CreateObject("ADODB.connection")
ConnStr= "Driver=Microsoft Visual Foxpro Driver;
UID=userID;SourceType=DBC;SourceDB=C:\path\to\database.dbc"
Conn.Open ConnStr
%>
Oracle:
I am just now experimenting with Oracle, and I hope to have more information available at a later
date. However, I've gotten as far as connecting to an Oracle database and successfully displayed
records, so that's a start :) I have found, however, that (1) you really have to use cursorlocation or
things do not work too well and (2) OLEDB is very cool.
ODBC with DSN:
<%
set conn=server.createobject("adodb.connection")
conn.cursorlocation=adUseClient ' requires use of adovbs.inc; numeric value is 3
conn.open "DSN=your_DSN_name;UID=kathi;PWD=xxxxxx"
%>
OLEDB
<%
set conn=server.createobject("adodb.connection")
conn.cursorlocation=adUseClient ' requires use of adovbs.inc; numeric value is 3
DSNTemp="Provider=MSDAORA.1;Password=xxxxx;User ID=kathi;Data Source=xxx.world"
conn.open DSNtemp
%>