gpt4 book ai didi

sql - ASP Q :Executing SQL query failed after MsSQL DB connection

转载 作者:搜寻专家 更新时间:2023-10-30 23:33:09 24 4
gpt4 key购买 nike

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

<!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>

但是出现了不可理解的错误。

enter image description here

系统环境:

Server 2008 Ver 6.0 x86

Mozila Firefox Web Browser 52.0

Sublime Text 3

提前谢谢你。

最佳答案

你的代码没有错。

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

我搭建了这个环境,按照你的方法试了一下,出现了这个错误。这不是解决方案吗?

Set en-coding on your page or your browser.

The character encoding of the HTML document was not declared

按F12查看!

使 SqlQuery 直接连接到数据库。

例如:)

PWD=*****;DATABASE=TestDataBase;"
SELECT * FROM TestTable

执行 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

关于sql - ASP Q :Executing SQL query failed after MsSQL DB connection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46362144/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com