asp中各种数据库连接代码
1.创建有ODBC数据源的连接
第一种情况:用dsn连接并且没有用户名和密码
<%
Dim db
Set db=Server.CreateObject("ADODB.Connection")
Db.Open "addr"
%>
第二种情况:用dsn连接并且有用户名和密码
<%
set conn = server.createobject("adodb.connection")
conn.open "yourdsnname","username","password"
%>
2.用实际的数据库绝对路径连接:
<%
set conn = server.createobject("adodb.connection")
strconn="driver=;"
strconn=strconn & "dbq=e:\yanhang\database.mdb"
conn.open strconn
%>
3.用实际的数据库相对路径连接:
<%
set conn = server.createobject("adodb.connection")
strconn="driver=; "
strconn=strconn & "dbq=" & server.mappath("/database/yanhang.mdb")
conn.open strconn
%>
4.创建没有ODBC数据源的连接
<%
Dim db
Set db=Server.CreateObject("ADODB.Connection")
Db.Open "Dbq=" & Server.Mappath("address.mdb") & ";Driver={Microsoft Access Driver (*.mdb)}"
%>
或者:
<%
Dim db
Set db=Server.CreateObject("ADODB.Connection")
Db.Open "Dbq=" & Server.Mappath("address.mdb") & ";Driver={Microsoft Access Driver (*.mdb)}"
%>
5.创建基于OLEDB的连接:
<%
Dim db
Set db=Server.CreateObject("ADODB.Connection")
Db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= address.mdb"
%>
第一种情况:用dsn连接并且没有用户名和密码
<%
Dim db
Set db=Server.CreateObject("ADODB.Connection")
Db.Open "addr"
%>
第二种情况:用dsn连接并且有用户名和密码
<%
set conn = server.createobject("adodb.connection")
conn.open "yourdsnname","username","password"
%>
2.用实际的数据库绝对路径连接:
<%
set conn = server.createobject("adodb.connection")
strconn="driver=
strconn=strconn & "dbq=e:\yanhang\database.mdb"
conn.open strconn
%>
3.用实际的数据库相对路径连接:
<%
set conn = server.createobject("adodb.connection")
strconn="driver=
strconn=strconn & "dbq=" & server.mappath("/database/yanhang.mdb")
conn.open strconn
%>
4.创建没有ODBC数据源的连接
<%
Dim db
Set db=Server.CreateObject("ADODB.Connection")
Db.Open "Dbq=" & Server.Mappath("address.mdb") & ";Driver={Microsoft Access Driver (*.mdb)}"
%>
或者:
<%
Dim db
Set db=Server.CreateObject("ADODB.Connection")
Db.Open "Dbq=" & Server.Mappath("address.mdb") & ";Driver={Microsoft Access Driver (*.mdb)}"
%>
5.创建基于OLEDB的连接:
<%
Dim db
Set db=Server.CreateObject("ADODB.Connection")
Db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= address.mdb"
%>