数据库连接错误,请检查连接字符串。

jx633 2009-08-14 11:10:02
网址是:http://www.club315.com/
大家可以看到有二个模块是提示 “ 数据库连接错误,请检查连接字符串。”
我也改过数据库的名称,但始终不对,麻烦大家给我看下。

' 可修改设置一:========================定义数据库类别,1为SQL数据库,0为Access数据库=============================
Const IsSqlDataBase = 0

If IsSqlDataBase = 1 Then
' 必修改设置二:========================SQL数据库设置=============================================================
' sql数据库连接参数:数据库名(SqlDatabaseName)、用户密码(SqlPassword)、用户名(SqlUsername)、
' 连接名(SqlLocalName)(本地用local,外地用IP)
Const SqlDatabaseName = "iXuEr_Pams_1" ' 数据库名
Const SqlUsername = "iXuEr_Studio" ' 用户名
Const SqlPassword = "iXuEr_Studio" ' 用户密码
Const SqlLocalName = "(local)" ' 连接名
' ================================================================================================================
SqlNowString = "GetDate()"
Else
' 必修改设置三:========================Access数据库设置==========================================================
' 用户第一次使用请在这里修改数据库地址和名称
DBPath = "../DB/"
DB = DBPath & "#nowshop.asp"
' ================================================================================================================
SqlNowString = "Now()"
End If
' ============================================
' 函数名称:ConnectionDatabase
' 函数功能:为全站创建主数据库连接
' ============================================
Function ConnectionDatabase()
On Error Resume Next
If IsSqlDataBase = 1 Then
ConnStr = "Provider = Sqloledb; User ID = " & SqlUsername & "; Password = " & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source = " & SqlLocalName & ";"
Else
'第一次使用请修改本处数据库地址并相应修改data目录中数据库名称
ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(MyRootPath & DB)
End If

Set Conn = Server.CreateObject(ServerObject_001)
Conn.Open ConnStr

If Err Then
Err.Clear
Set Conn = Nothing
Response.Write("数据库连接错误,请检查连接字符串。")
'Response.Write("The database connection error , please check the connection character string .")
Response.End()
End If
End Function
...全文
1116 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
mailbao 2009-08-14
  • 打赏
  • 举报
回复
檢查你的數據庫路徑是否正確
即這一句

ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(MyRootPath & DB)

其中這個MyRootPath是否指定本機的地址了?
而DB路徑是否OK?
anbs01 2009-08-14
  • 打赏
  • 举报
回复
Conn.Open ConnStr
的下面加上
response.write("err.description")
看看是什么。
jx633 2009-08-14
  • 打赏
  • 举报
回复
嗯 说的是
可以结贴了
mailbao 2009-08-14
  • 打赏
  • 举报
回复
汗.....lz.//

現在總算連上數據庫了...
不過你的數據表...
報錯信息都有提示錯誤的原因啦,你自己對照下數據表是不是寫正確了不就得啦??
jx633 2009-08-14
  • 打赏
  • 举报
回复
去掉之后的提示为

查询语句为:select * from t_MagColor
错误信息为:Microsoft Jet 数据库引擎找不到输入表或查询 't_MagColor'。 确定它是否存在,以及它的名称的拼写是否正确。
mailbao 2009-08-14
  • 打赏
  • 举报
回复
注意以下3點問題:

[Quote=引用 12 楼 jx633 的回复:]
哈哈。。太快了就是容易失误。。

这下的提示为: " ../DB/#nowshop.asp "
[/Quote]

http://www.club315.com/mag.asp

<!-- #include file="inc/conn.asp" -->


-------------------------------------------------

很明顯就看出你的數據庫放的位置和實際引用的路徑不一樣!!
mag.asp與DB文件夾同一目錄,可剛才叫你調試時DB的路徑是" ../DB/#nowshop.asp "

如果去掉../,即改為DB/#nowshop.asp才可以正常訪問!!
jx633 2009-08-14
  • 打赏
  • 举报
回复
你可以看下网址 http://www.club315.com/


下面是mag.asp文件的全部代码
<!-- #include file="inc/conn.asp" -->
<!--%=iXs.ShowIDName("t_Mag","MagId","MagName",MagId)%-->
<link href="inc/style.css" rel="stylesheet" type="text/css" />
<script src="inc/style.js"></script></head>
<%
dim rsMag,sqlMag,sMagtype,sSort,sOrder
dim sMagCount,sPageIndex,sPageSize,sPageCount,iMag

sMagType = Trim(request("t"))
sPageIndex = Trim(request("p"))
sSort = Trim(request("s"))

if sMagType = "" then
sqlMag = "select Top 1 * from t_Mag where Flag = 1 ORDER BY PublishDate DESC, MagId DESC"
else
sqlMag = "select Top 1 * from t_Mag where Flag = 1 and TypeCode = '"&sMagType&"'"
sqlMag = sqlMag + " ORDER BY PublishDate DESC, MagId DESC"
end if
%>

<table width="98%" border="0" cellspacing="1" cellpadding="1">
<tr>
<%
if sPageIndex = "" then sPageIndex = 0
if sSort = "2" then
sOrder = "TotalView"
else
sOrder = "PublishDate"
end if

if sMagType = "" then
sqlMag="select Count(MagId) from t_Mag where Flag = 1"
else
sqlMag="select Count(MagId) from t_Mag where Flag = 1 and TypeCode = '"&sMagType&"'"
end if

set rsMag = iXs.GetRs(sqlMag,1,1)
sMagCount = rsMag(0)
rsMag.close

sPageSize = 12

sPageCount = int(sMagCount / sPageSize)

if sMagType = "" then
if sPageIndex = 0 then
sqlMag = "select Top "&CStr(sPageSize)&" * from t_Mag where Flag = 1"
sqlMag = sqlMag + " ORDER BY "&sOrder&" DESC, MagId"
else
sqlMag = "select Top "&CStr(sPageSize)&" * from t_Mag where Flag = 1"
sqlMag = sqlMag + "and MagId NOT IN (SELECT TOP " & CStr(sPageSize * sPageIndex)
sqlMag = sqlMag + " MagId FROM t_Mag WHERE Flag = 1 ORDER BY "&sOrder&" DESC, MagId)"
sqlMag = sqlMag + " ORDER BY "&sOrder&" DESC, MagId"
end if
else
if sPageIndex = 0 then
sqlMag = "select Top "&CStr(sPageSize)&" * from t_Mag where Flag = 1 and TypeCode = '"&sMagType&"'"
sqlMag = sqlMag + " ORDER BY "&sOrder&" DESC, MagId"
else
sqlMag = "select Top "&CStr(sPageSize)&" * from t_Mag where Flag = 1 and TypeCode = '"&sMagType&"'"
sqlMag = sqlMag + "and MagId NOT IN (SELECT TOP " & CStr(sPageSize * sPageIndex)
sqlMag = sqlMag + " MagId FROM t_Mag WHERE Flag = 1 and TypeCode = '"&CStr(sMagType)&"' ORDER BY "&sOrder&" DESC, MagId)"
sqlMag = sqlMag + " ORDER BY "&sOrder&" DESC, MagId"
end if
end if

set rsMag = iXs.GetRs(sqlMag,1,1)

iMag = 0
do while not rsMag.eof and iMag<5
%>
<TD><%=MagShow(rsMag("MagId"),rsMag("SmallImgUrl"),rsMag("MagName"),rsMag("PublishDate"),rsMag("Pages"),rsMag("TotalView"))%></TD>

<%
iMag = iMag + 1
'if iMag > 5 then
'Response.Write "</tr><tr>"
'iMag = 0
'end if
rsMag.movenext
loop
rsMag.close
%>
</tr>
</table>
mailbao 2009-08-14
  • 打赏
  • 举报
回复
這個MyRootPath沒有值??

按理會有網址的 http://localhost/web/ 你得查查這個在哪用過.


另外,現在知道了數據庫的,就可以在哪個頁面運行報錯裏進行斷點調試測出問題的根源了.

按估計,報錯的程序頁面多是你引用conn.asp時,數據庫的地址不對造成的,自己檢查下就知道了.

jx633 2009-08-14
  • 打赏
  • 举报
回复
哈哈。。太快了就是容易失误。。

这下的提示为: " ../DB/#nowshop.asp "
mailbao 2009-08-14
  • 打赏
  • 举报
回复
打字快少打了個連接符號&,再試

response.write MyRootPath&" <br/>"&DB
response.end
jx633 2009-08-14
  • 打赏
  • 举报
回复
提示为:
Microsoft VBScript 编译器错误 错误 '800a0401'

语句未结束

/inc/conn.asp,行 85

response.write MyRootPath&" <br/>"DB
----------------------------------^、

85行就是我刚刚加入你说的这二行代码的地方。
mailbao 2009-08-14
  • 打赏
  • 举报
回复
在程序中斷點調試下
response.write MyRootPath&"<br/>"DB
response.end

看看你現在代碼中讀取的數據庫路徑是什麼?然後再對症修改其路徑,應該是你的站點目錄(MyRootPath)+相對路徑(DB)與實際的數據庫不一致造成的!
jx633 2009-08-14
  • 打赏
  • 举报
回复
我就是在这里改了 还是失败 所以才头痛
mailbao 2009-08-14
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jx633 的回复:]
引用 2 楼 mailbao 的回复:
檢查你的數據庫路徑是否正確
即這一句

ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(MyRootPath & DB)

其中這個MyRootPath是否指定本機的地址了?
而DB路徑是否OK?



你说对了,就是在这一句。
数据库的名称是“#nowshop.asp”  但问题是我不知道应该填写在这句代码中的哪个地方
[/Quote]



修改處如下示:


<%
......

' 必修改设置三:========================Access数据库设置==========================================================
' 用户第一次使用请在这里修改数据库地址和名称
DBPath = "../DB/"
DB = DBPath & "#nowshop.asp"
' ================================================================================================================

......
%>

jx633 2009-08-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 ywfsoft 的回复:]
看看这个吧,可能对你有用
http://hi.baidu.com/ywfsoft/blog/item/ab2571f813e8d606d8f9fd6b.html
[/Quote]

谢谢你的回复,与这个无关的。权限都是好好的
jx633 2009-08-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 mailbao 的回复:]
檢查你的數據庫路徑是否正確
即這一句

ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(MyRootPath & DB)

其中這個MyRootPath是否指定本機的地址了?
而DB路徑是否OK?

[/Quote]

你说对了,就是在这一句。
数据库的名称是“#nowshop.asp” 但问题是我不知道应该填写在这句代码中的哪个地方
jx633 2009-08-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 anbs01 的回复:]
Conn.Open ConnStr
的下面加上
response.write("err.description")
看看是什么。
[/Quote]


提示为:err.description数据库连接错误,请检查连接字符串。
ywfsoft 2009-08-14
  • 打赏
  • 举报
回复
看看这个吧,可能对你有用
http://hi.baidu.com/ywfsoft/blog/item/ab2571f813e8d606d8f9fd6b.html

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧