ASP连接Access数据库的几种方法
程序员文章站
2023-12-23 21:06:09
1. 相对与比较老的环境,建议使用第二个
set dbconnection=server.createobject("adodb.connection")
d...
1. 相对与比较老的环境,建议使用第二个
set dbconnection=server.createobject("adodb.connection") dbpath = server.mappath("customer.mdb") dbconnection.open "driver={microsoft access driver (*.mdb)};dbq=" & dbpath sql="select * from auth where id='" & user_id &"'" set uplist=dbconnection.execute(sql)
2.win2003以上的机器,建议用此方法,效率更高
set dbconnection=server.createobject("adodb.connection") dbpath = server.mappath("customer.mdb") dbconnection.open "provider=microsoft.jet.oledb.4.0;data source="&dbpath sql="select * from auth where id='" & user_id &"'" set uplist=dbconnection.execute(sql)
3.
dbpath = server.mappath("customer.mdb") set session("rs")=server.createobject("adodb.recordset") ' rs=server.createobject("adodb.recordset") connstr="provider=microsoft.jet.oledb.4.0;data source="&dbpath sql="select * from auth where id='" & user_id &"'" session("rs").open sql,connstr,1,3
4. 建odbc源xxx
set conn=server.createobject("adodb.connection") conn.open "dsn=xxx;uid=;pwd=;database=customer
5、附上一个经常用的sqlserver与access通用的连接数据库代码
<% const databasetype=1 if databasetype=0 then dbpath="/jb51/news.asp" sqlnowstring = "now()" ystr=true nstr=false suiji="rnd(id)" else '如果是sql数据库,请认真修改好以下数据库选项 dataserver = "wwwjb51net" '数据库服务器ip datauser = "jb51net" '访问数据库用户名 databasename = "jb51net" '数据库名称 databasepsw = "密码" '访问数据库密码 sqlnowstring = "getdate()" ystr=1 nstr=0 suiji="newid()" end if on error resume next if databasetype = 1 then connstr="driver={sql server};server="&dataserver&";uid="&datauser&";pwd="&databasepsw&";database="&databasename else connstr = "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(dbpath) end if set conn = server.createobject("adodb.connection") conn.open connstr if err then err.clear:set conn = nothing:response.write "数据库连接出错,请检查conn.asp文件中的数据库参数设置。":response.end %>