MS Access数据库连接
用DSN连接并且没有用户名和密码:
[CODE_LITE]<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "YourDSNName"
%>[/CODE_LITE]
用DSN连接并且有用户名和密码:
[CODE_LITE]<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "YourDSNName","username","password"
%>[/CODE_LITE]
用实际的数据库绝对路径连接:
[CODE_LITE]<%
Set conn = Server.CreateObject("ADODB.Connection")
Strconn="DRIVER={Microsoft Access Driver (*.mdb)}; "
Strconn=Strconn & "DBQ=e:yanhangdatabase.mdb"
conn.Open Strconn
%>[/CODE_LITE]
用实际的数据库相对路径连接:
[CODE_LITE]<%
Set conn = Server.CreateObject("ADODB.Connection")
Strconn="DRIVER={Microsoft Access Driver (*.mdb)}; "
Strconn=Strconn & "DBQ=" & Server.MapPath("/database/yanhang.mdb")
conn.Open Strconn
%>[/CODE_LITE]
MS SQL Server数据库连接
用DSN连接:
[CODE_LITE]<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "DSN=MyDSN;UID=user;PWD=password;DATABASE=databasename"
%>[/CODE_LITE]
不用DSN连接:
[CODE_LITE]<%
Set conn = Server.CreateObject("ADODB.Connection")
DSNtemp="DRIVER={SQL Server};SERVER=ServerName;UID=USER;PWD=password;DATABASE=databasename"
conn.open DSNtemp
%>[/CODE_LITE]
FoxPro数据库连接
[CODE_LITE]<%
Set Conn = Server.CreateObject("ADODB.connection")
ConnStr= "Driver=Microsoft Visual Foxpro Driver; UID=userID;SourceType=DBC;SourceDB=C:yanhangdatabase.dbc"
Conn.Open ConnStr
%>[/CODE_LITE]
Oracle数据库连接:
[CODE_LITE]<%
set conn=server.createobject("adodb.connection")
conn.cursorlocation=adUseClient
DSNTemp="Provider=MSDAORA.1;Password=xxxxx;User ID=yanhang;Data Source=xxx.world"
conn.open DSNtemp
%>[/CODE_LITE]
转载请注明:HANLEI'BLOG » 各种数据库ASP连接代码