有没有大神知道ASP VBscript连接access数据库代码怎么写
展开全部
下面是搭袭我的conn.asp, 以前是mdb的现在改sql, 你应该看得懂, mdb有两种连接方式, OLEDB和DBQ都可以运行
所有文件在首行引用即可
<!--#include file=conn.asp-->
------conn.asp------
<%
Option Explicit
Response.Buffer = True
Dim rs,rs1,rs2,rs3,rs4,rs5,Db,DbPath,MyDbpath,adoConn,adoConn1,Sql,sql1,sql2,sql3,sql4,admin_name,admin_pass,username,password
Dim local(30)
MyDbPath = "192.168.38.141"
Db = "DickDB"
'Db = "\\192.168.38.153\database\H#R.mdb"
Const EnabledSession= true
Const IsDeBug = 1
Sub ConnectionDatabase
Dim ConnStr
'ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source =" & db & ";Jet OLEDB:Database Password='tommy'"
'ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source =" & Server.MapPath(MyDbPath & db) & ";Jet OLEDB:Database Password='tommy';admin"腔空
'connstr = "DBQ=" + server.mappath(""&db&"") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};password='tommy'"
ConnStr = "Provider=SQLOLEDB;Data Source=192.168.38.141;User ID=webasp02;Password=webasp02#;Database=DicksonSHDB"
Set adoconn = server.CreateObject("ADODB.Connection"知圆兄)
adoconn.open ConnStr
If Err Then
Response.Write err.description & err.number
err.Clear
Set adoConn = Nothing
'Response.Write "Database Error, Please contact the IT Department!"
Response.End
End If
End Sub
%>
所有文件在首行引用即可
<!--#include file=conn.asp-->
------conn.asp------
<%
Option Explicit
Response.Buffer = True
Dim rs,rs1,rs2,rs3,rs4,rs5,Db,DbPath,MyDbpath,adoConn,adoConn1,Sql,sql1,sql2,sql3,sql4,admin_name,admin_pass,username,password
Dim local(30)
MyDbPath = "192.168.38.141"
Db = "DickDB"
'Db = "\\192.168.38.153\database\H#R.mdb"
Const EnabledSession= true
Const IsDeBug = 1
Sub ConnectionDatabase
Dim ConnStr
'ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source =" & db & ";Jet OLEDB:Database Password='tommy'"
'ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source =" & Server.MapPath(MyDbPath & db) & ";Jet OLEDB:Database Password='tommy';admin"腔空
'connstr = "DBQ=" + server.mappath(""&db&"") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};password='tommy'"
ConnStr = "Provider=SQLOLEDB;Data Source=192.168.38.141;User ID=webasp02;Password=webasp02#;Database=DicksonSHDB"
Set adoconn = server.CreateObject("ADODB.Connection"知圆兄)
adoconn.open ConnStr
If Err Then
Response.Write err.description & err.number
err.Clear
Set adoConn = Nothing
'Response.Write "Database Error, Please contact the IT Department!"
Response.End
End If
End Sub
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<%
Dim dbFileName
dbFileName = "data/#data.mdb"
'上颂卖李面改成数据库目录
Dim dbFilePath
dbFilePath = Server.MapPath(dbFileName)
On Error Resume Next
Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbFilePath
If Err Then
Err.Clear
Response.write ("数配贺据库出错"野迟)
Response.end
Set Conn = Nothing
conn.close
End If
%>
Dim dbFileName
dbFileName = "data/#data.mdb"
'上颂卖李面改成数据库目录
Dim dbFilePath
dbFilePath = Server.MapPath(dbFileName)
On Error Resume Next
Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbFilePath
If Err Then
Err.Clear
Response.write ("数配贺据库出错"野迟)
Response.end
Set Conn = Nothing
conn.close
End If
%>
更多追问追答
追问
代码放在哪里
追答
把你的代码复制上来看看,一般是用我的代码替换conn.asp或者conn.inc的代码
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |