这是一个显示聊天内容的程序,chatissue.asp
<%
dim ConnStr,RecUser,SQLstr
Set RecUser = server.CreateObject("ADODB.RecordSet")
ConnStr = "DNS=chat2;"
SQLstr = "Select * from content"
RecUser.Open SQLstr,ConnStr,adopenstatic '第15行
do while not RecUser.EOF
if RecUser.Fields("isprivate") = true then
Response.Write"<font color=bule>" & RecUser.Fields("userid") & "私下对" & RecUser.Fields("friendid") & "说:</font>" & RecUser.Fields("content") & "<br>"
else
Response.Write RecUser.Fields("userid") & "对" & RecUser.Fields("userid") & "说:" & RecUser.Fields("content") & "<br>"
end if
RecUser.MoveNext
loop
RecUser.Close
Set RecUser = Nothing
%>
报错:
Microsoft OLE DB Provider for ODBC Drivers 错误 '***********'
[Microsoft][ODBC 驱动程序 管理器] 未发现数据源名称并且未指定默认驱动程序
/ht/chatissue.asp, 行15
数我用的access据库连接没有错误,测试程序可以显示数据库中的内容
-----------------------------------------------------
这是输入聊天内容的程序,输入内容后数据库没有添加任何信息
<%
dim ii,jj,intNum
dim strname,friendid
dim username(100)
dim col,temporder
dim connstr,recuser,sqlstr
connstr="DSN=chat2;"
set recuser=server.CreateObject("ADODB.RecordSet")
sqlstr = "select * from user where isenter = true"
RecUser.Open sqlstr,connstr,adopenstatic
intNum = 0
do while not RecUser.EOF
intNum = intNum + 1
username(intNum) = RecUser.Fields("userid")
RecUser.MoveNext
loop
recuer.close
if Request.form("cmdsend") = "提交" then
sqlstr = "select * from content"
recuser.Open sqlstr,connstr,adopendynamic,adlockoptimistic
recuser.AddNew
recuser.fields("userid") = session("userid")
recuser.fields("content") = request.form("txtmark")
recuser.fields("speaktime") = NOW()
recuser.fields("friendid") = request.form("cbofriend")
recuser.Update
if Request.form("chkprivate") = "on" then
recuser.fields("isprivate") = true
else
recuser.fields("isprivate") = false
end if
recuser.Close
end if
set recuser = Nothing
%>
这两段代码都有错误,且相互联系,但我不知道问题出在哪
參考答案:Set RecUser = server.CreateObject("ADODB.RecordSet")
ConnStr = "DNS=chat2;"
这个要看你有没有建数据源了。
最好是不要用数据源,
你可以修改成这样:
1.如果是ACCESS数据库
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" _
& Server.MapPath("数据库名.mdb")
set conn = server.createobject("adodb.connection")
conn.open strconn
2.如是sqlserver数据库刚为
strconn = "Driver={SQL Server};Description=sqldemo;SERVER=127.0.0.1;" _
&"UID=sa;Password=sa;DATABASE=Database_Name"
set conn = server.createobject("adodb.connection")
conn.open strconn