在预览asp时提示:数据库连接出错[代码:01],请检查数据库链接文件中的连接字串
错误代码:starttime=timer()DbType="ACCESS"'链接ACCESS数据库DbType="ACCESS"DB="DataBases/data.md...
错误代码:
starttime=timer()
DbType = "ACCESS" '链接ACCESS数据库
DbType="ACCESS"
DB = "DataBases/data.mdb"
ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(db)
On Error Resume Next
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错[代码:01],请检查数据库链接文件中的连接字串。"
Response.End
End If
%> 展开
starttime=timer()
DbType = "ACCESS" '链接ACCESS数据库
DbType="ACCESS"
DB = "DataBases/data.mdb"
ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(db)
On Error Resume Next
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错[代码:01],请检查数据库链接文件中的连接字串。"
Response.End
End If
%> 展开
3个回答
展开全部
给你个asp通用链接文件,可以连接access或sql
<%
dim conn
dim connstr
dim db
db=""&db_All&"" '设定数据库位置和名称,用于access
dim dbset:setdb = 1 '设定连接类型
On error resume next
Set conn = Server.CreateObject("ADODB.Connection")
select case setdb
case "1"
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
case "2"
connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(""&db&"")
case "3"
connstr="driver={SQL Server};server=localhost;UID=sa;PWD=123;database=data"
case else
connstr= "driver={SQL Native Client};server=localhost;UID=sa;PWD=123;database=data"
end select
if err.number>0 then
err.clear
set conn=nothing
response.write "数据库连接出错!"
Response.End
else
conn.open connstr
if err then
err.clear
set conn=nothing
response.write "数据库连接出错!"
Response.End
end if
end if
Sub CloseConn()
conn.close
set conn=nothing
End sub
%>
其他页面用
<!--#include file="head.asp" -->调用上面这个文件
<%
dim conn
dim connstr
dim db
db=""&db_All&"" '设定数据库位置和名称,用于access
dim dbset:setdb = 1 '设定连接类型
On error resume next
Set conn = Server.CreateObject("ADODB.Connection")
select case setdb
case "1"
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(""&db&"")
case "2"
connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(""&db&"")
case "3"
connstr="driver={SQL Server};server=localhost;UID=sa;PWD=123;database=data"
case else
connstr= "driver={SQL Native Client};server=localhost;UID=sa;PWD=123;database=data"
end select
if err.number>0 then
err.clear
set conn=nothing
response.write "数据库连接出错!"
Response.End
else
conn.open connstr
if err then
err.clear
set conn=nothing
response.write "数据库连接出错!"
Response.End
end if
end if
Sub CloseConn()
conn.close
set conn=nothing
End sub
%>
其他页面用
<!--#include file="head.asp" -->调用上面这个文件
展开全部
On Error Resume Next
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错[代码:01],请检查数据库链接文件中的连接字串。"
Response.End
End If
把这段删掉看看提示什么错
On Error Resume Next 加上这句的话错误信息是会被屏蔽的!
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错[代码:01],请检查数据库链接文件中的连接字串。"
Response.End
End If
把这段删掉看看提示什么错
On Error Resume Next 加上这句的话错误信息是会被屏蔽的!
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
标准的链接代码:
<%
dim DBName,conn,connstr
DBName="data.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(DBName)
conn.Open connstr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write"数据库连接出错,请检查连接字串!"
Response.End
End If
%>
<%
dim DBName,conn,connstr
DBName="data.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(DBName)
conn.Open connstr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write"数据库连接出错,请检查连接字串!"
Response.End
End If
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询