欧洲进口家具:精通ASP的高手进!!!数据库的小问题???

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 06:47:54
本人最近开始学ASP,按照书上的步骤一步一步的做,
例子是这样的:用Access做个学生通讯录,然后在网页上显示出来
我用ODBC连接的数据库,绝对在"管理工具"-"数据源 (ODBC)"-"系统DSN"标签里设置过了
结果出现如下现象:
Microsoft OLE DB Provider for ODBC Drivers 错误 '80004005'

[Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序

/showdata.asp,行 8

我改用OLEDB连接数据库将一切正常.
这到是为什么!!!谁能告诉我

<下面是程序的代码> (ODBC连接)

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Connections/connDSN.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_connDSN_STRING
Recordset1.Source = "SELECT * FROM 学生通讯录"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<table width="672" height="59" border="0" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<tr>
<td><%=(Recordset1.Fields.Item("座号").Value)%></td>
<td><%=(Recordset1.Fields.Item("姓名").Value)%></td>
<td><%=(Recordset1.Fields.Item("电子邮件").Value)%></td>
<td><%=(Recordset1.Fields.Item("性别").Value)%></td>
<td><%=(Recordset1.Fields.Item("生日").Value)%></td>
<td><%=(Recordset1.Fields.Item("电话").Value)%></td>
<td><%=(Recordset1.Fields.Item("住址").Value)%></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>

</table>

</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>

问题在于你的第二行
<!--#include file="Connections/connDSN.asp" -->
这个conndsn.asp是数据库连接文件,你应该把这个文件的内容贴出来,不过一般来说,出这个错误说明你这个数据库连接出了问题,给你我的程序用的连接语句
<%
db="Database/123.mdb"
set conn=server.createobject("adodb.connection")
dbpath=server.mappath(db)
conn.open"DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&dbpath
set rs =server.createobject("adodb.recordset")
function CloseDatabase
Conn.close
Set conn = Nothing
End Function
%>