ASP 在数据库中访问 table,SQL Server Management Studio 2016

ASP access a table in a database , SQL Server Management Studio 2016

我正在尝试构建一个可以检索数据并将数据插入数据库的经典 ASP(不是 asp.net)页面。我遵循了一些在线示例并设法连接到我的数据库。这是我的 ASP 页面中的以下代码。

<!DOCTYPE html>
<html>
<body>
<%

Set Con= CreateObject("ADODB.Connection")
Con.ConnectionString= "Provider=SQLOLEDB; Data Source=PCNAME\SQLEXPRESS;Database=testing;User ID=sa;password=abcdefg"
Con.open

if IsObject(Con) then 
response.Write "The connection is active <br/>"

if Con.State=1 then
response.Write "A connection is made and is open <br/>"
end if

%>

</body>
</html>

加载后,asp 页面显示

"The connection is active A connection is made and is open"

现在,我想创建一个记录集并从中提取数据。

我将这段代码添加到我的代码中,

set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn

但是,当我加载页面时,我得到以下结果,

The connection is active A connection is made and is open An error occurred on the server when processing the URL. Please contact the system administrator.

If you are the system administrator please click here to find out more about this error.

好吧,如果您在此处提交的代码是您真正使用的代码,那么您会收到一个错误,因为 ADODB.Connection 对象在 rs.Open 行中,错误说明是:

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

因为您创建了一个连接名称 Con 并将 conn 传递给了 rs.Open 的第二个参数,它需要一个连接字符串或一个连接对象。

在此处阅读更多内容: http://www.w3schools.com/asp/met_rs_open.asp