尝试在经典ASP中调用存储过程时出现3709错误

时间:2017-11-29 17:25:55

标签: stored-procedures vbscript asp-classic

我正在尝试从经典ASP应用程序调用存储过程,并且我收到3709错误。这是一个连接不能......错误。

On Error Resume Next
set ConnectionStr = "driver=SQL Server;server=***;uid=***;pwd=***;database=***"

Set cmd = Server.CreateObject("ADODB.Command")
With cmd
    Set .ActiveConnection = ConnectionStr
    .CommandType = adCmdStoredProc
    .CommandText = "storedprocedure"  

    'Input Parameters
    .Parameters.Append .CreateParameter("@email", adVarchar, adParamInput, 50, Request.Form("email")) 
    .Parameters.Append .CreateParameter("@pass", adVarchar, adParamInput, 50, Request.Form("password")) 

End With 

set rs = Server.CreateObject("ADODB.RecordSet") 

'rs.Open cmd.Execute
set rs = cmd.Execute 'Here is 3709 Error

If not rs.eof Then 'I get a 3704 Error here because of the 3709 error above
    'Do Things with the RS
End If
Set cmd = Nothing

我的存储过程是:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[nameofprocedure]
    @email nvarchar(50),
    @pass nvarchar(50)
AS
BEGIN
    SET NOCOUNT ON
    SELECT is, fstname, lstname, [password]
    FROM users
    WHERE email = @email AND [password] = @pass;
    RETURN
END

3 个答案:

答案 0 :(得分:1)

您需要创建并打开连接。试试这段代码:

Set ConnectionStr = Server.CreateObject("ADODB.Connection")  
ConnectionStr.Open "driver=SQL Server;server=***;uid=***;pwd=***;database=***"

您可能希望将变量重命名为其他变量,因为它不是真正的连接字符串。

答案 1 :(得分:1)

错误的原因是ConnectionStr是字符串变量而不是对象变量,因此不期望Set。你有两个选择;

  1. Set开头删除ConnectionStr

    set ConnectionStr = "driver=SQL Server;server=***;uid=***;pwd=***;database=***"
    

    ConnectionStr = "driver=SQL Server;server=***;uid=***;pwd=***;database=***"
    
  2. 在这种情况下实例化一个对象变量,它将是ADODB.Connection,您必须在传递连接字符串时调用Open()方法(除非您重新使用这个连接对象有点过分了)Brian covers this in their answer

  3. 有用的链接

答案 2 :(得分:0)

ASP文件缺少对ADO数据对象的库引用。

<!--METADATA
TYPE="TypeLib"
NAME="Microsoft ActiveX Data Objects 2.6 Library"
UUID="{00000206-0000-0010-8000-00AA006D2EA4}"
VERSION="2.6"
-->