86版聊斋 百度云盘:ASP连接数据库的语句

来源:百度文库 编辑:高校问答 时间:2024/05/07 06:20:55
我在SQL SERVER中做了个表,表名叫TABLE1,数据库名叫Exercise,我在系统DSN中建的源的名字叫ASPTest,我计算机的名字叫microsof-962462
数据库的UID是sa 密码是admin,我连了一下也不成功,请问如何才能连上SQL啊,快被他弄疯了.
下面是我写的代码
<html>
<head>
<title>修改及删除记录综合实例</title>
</head>
<body>
<%
Dim cn,rs
Dim mySql
Set cn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.RecordSet")
cn.Open "Driver={SQL Server};Server=microsof-962462.;Database=ASPTest;" & _
"UID=sa;PWD=admin"
rs.Open "SELECT * FROM TABLE1",cn
%>
<p align="center">已注册ID列表</p>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="391" align=center>
<tr>
<td width="97">注册ID</td>
<td width="97">注册密码</td>
<td width="77">Email地址</td>
<td width="60">操作1</td>
<td width="56">操作2</td>
</tr>
<%
Do While Not rs.Eof
%>
<tr>
<td width="97"><%=rs(0)%> </td>
<td width="97"><%=rs(1)%> </td>
<td width="77"><%=rs(2)%> </td>
<td width="60"><a href="09_04a.asp?txtID=<% =rs(0) %>">修改</a></td>
<td width="56"><a href="09_04c.asp?txtID=<% =rs(0) %>">删除</a></td>
</tr>
<%
rs.MoveNext
Loop
%>
</table>
<%
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
%>
</body>
</html>
显示的错误是
错误类型:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC SQL Server Driver][SQL Server]无法打开登录 'ASPTest' 中请求的数据库。登录失败。
我把我的IP地址改成127.0.1后显示的还是这个错误,而且我在我的地址栏上打上127.0.1的时候还会显示一个姓名和密码的对话框,也没有的打开.真是郁闷

我在SQLServer(用户名sa密码空)中有数据库test下表info,将你的代码连接串改为
cn.Open "Driver={SQL Server};Server=127.0.0.1;Database=test;" & _
"UID=sa;PWD="
rs.Open "SELECT * FROM info",cn
数据可以正常显示,说明代码的连接方法没有问题。你可以尝试用ip地址试试,由于权限等问题可能主机名解析不正确。还有很有可能是被防火墙拦截掉了,比如windows自带的防火墙等。

cn.Open "Driver={SQL Server};Server=microsof-962462.;Database=ASPTest;" & _
"UID=sa;PWD=admin"

SQL Server不需要建立系统DSN,在上面Database应该是SQL Server的数据库名,所以应改为Database=Exercise

把asptest改为Exercise试试