Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP Q:MsSQL数据库连接后执行SQL查询失败_Sql_Database_Web_Execute - Fatal编程技术网

ASP Q:MsSQL数据库连接后执行SQL查询失败

ASP Q:MsSQL数据库连接后执行SQL查询失败,sql,database,web,execute,Sql,Database,Web,Execute,我认为这是一个愚蠢的问题。也要知道这是一个重复的问题。但我不能解决这个问题。有人请帮帮我 <!DOCTYPE html> <html> <head> <title>DataBase Connection Example</title> </head> <body> <% Dim objConn 'Our Connection Object' Dim objRecd '

我认为这是一个愚蠢的问题。也要知道这是一个重复的问题。但我不能解决这个问题。有人请帮帮我

<!DOCTYPE html>
<html>
<head>
    <title>DataBase Connection Example</title>
</head>
<body>
<%
Dim objConn         'Our Connection Object'
Dim objRecd         'Our Recordest Object'
Dim strSQL          'Our SQL string to access the database'
Dim strConnection   'Out connection string to access the database'
Dim i               'A Counter Variable'

'---Create A Object---'
Response.Write("DB Connect Example<br>")
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRecd = Server.CreateObject("ADODB.RecordSet")
strConnection = "PROVIDER=SQLOLEDB;SERVER=127.0.0.1,1433;UID=sa;PWD=hello1995812;DATABASE=;"
Response.Write("Object Set<br>")

Response.Write("Connecting to DB<br>")
objConn.Open strConnection
Response.Write("Connected<br>")
strSQL = "SELECT * FROM master"
Response.Write("Executing...<br>")
Set objRecd = objConn.Execute(strSQL)
Response.Write("Executed<br>")

If (objRecd.BOF And objRecd.EOF) Then
    Response.Write("No Recoreds Found")
    Response.End
End If
Response.Write("<table border=1 cellpadding=2 cellspacing=1 width=100%")
Response.Write("<tr bgcolor=#CCCCCC>")
For i = 0 To objRecd.Fields.Count-1
    Response.Write("<th>" & objRecd.Fields(i).Name & "</th>")
Next
Response.Write("</tr>")
%>
</body>
</html>

数据库连接示例
但发生了不可理解的错误

系统环境:

服务器2008版本6.0 x86

Mozila Firefox Web浏览器52.0

崇高的文本3


提前谢谢。

您的代码没有错

但是,在查找错误之前,您必须先查看环境设置是否正确

我构建了这个环境,并按照您的方式进行了尝试,但出现了这个错误。这不是解决办法吗

在页面或浏览器上设置en编码

未声明HTML文档的字符编码

按F12键检查它

SqlQuery
设置为直接连接到数据库

例:)

之后执行SQL查询

If(objRecd.BOF And objRecd.EOF) Then
  Response.Write("No Records Found")
End If

For Each x In objRecd.Fields
  Response.Write(x.Name & "=" & x.value)
Next

使用MSSQL 2008的原因?但我不这么认为。你试过其他方法吗?连接不是不可能吗?很好,没有错误!但只显示了一行。如何显示总行数?@Kaizen,w3学校比我好@戈德诺夫请编辑答案,打印出所有结果。
If(objRecd.BOF And objRecd.EOF) Then
  Response.Write("No Records Found")
End If

For Each x In objRecd.Fields
  Response.Write(x.Name & "=" & x.value)
Next