ASP连接Access数据库的几种方法
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 %>
相关推荐
风之羽翼 2020-09-14
daillo 2020-04-20
踩风火轮的乌龟 2020-04-19
hithyc 2020-04-17
snowguy 2020-04-10
yhyily 2019-12-15
yangliuhbhd 2020-09-24
luotuofeile 2020-07-28
Strongding 2020-06-25
xuanwenchao 2020-06-14
昊 2020-06-04
ysmh00 2020-05-14
ErixHao 2020-05-08
数据库之扑朔迷离 2020-05-06
whyname 2020-04-29
hitxueliang 2020-04-18
zengfanpei 2020-03-08