jayu
jayu

Reputation: 337

Recordset in asp and execute stored procedure in asp

I want to open another .asp page from one .asp page on button click following is the code i have done but error is coming

Error is coming as "operation is not allowed when the object is closed"

Here is the code

 Dim dbconn, objCmd, objParam, rs, EmailID, Password, connString, RecordCount

 connString = "Connectionstring"

 dbconn = Server.CreateObject("ADODB.Connection")

 dbconn.Open(connString)

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

 objCmd = Server.CreateObject("ADODB.Command")
 objCmd.ActiveConnection = dbconn
 objCmd.CommandText = "sp_Name"
 objCmd.CommandType = &H0004 
 objParam = objCmd.CreateParameter("@EmailID",200,1,"100",Session("EmailID"))
 objCmd.Parameters.Append(objParam)

  objParam = objCmd.CreateParameter("@Password",200,1,"100",Session("Password"))
  objCmd.Parameters.Append(objParam)

   rs = objCmd.Execute(Session("EmailID"),Session("Password"))

   do while not rs.eof ------->here comes error 

    EmailID = rs(0)
    Password =  rs(1)
    'response.Write EmailID & "," & Password & "<br">
    rs.MoveNext
loop

Upvotes: 3

Views: 10009

Answers (2)

Kwangsoo
Kwangsoo

Reputation: 1

Here is my suggestion.

In my case, RecordSet object from Command.Execute() does not support .BOF nor EOF.

So, I use RecordSet.Open method to call a stored procedure like this....

Dim dbconn, objCmd, objParam, rs, EmailID, Password, connString, RecordCount
connString = "Connectionstring"
dbconn = Server.CreateObject("ADODB.Connection")
dbconn.Open(connString)

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

objCmd = Server.CreateObject("ADODB.Command")
objCmd.ActiveConnection = dbconn
objCmd.CommandText = "sp_Name"
objCmd.CommandType = &H0004 
objParam = objCmd.CreateParameter("@EmailID",200,1,"100",Session("EmailID"))
objCmd.Parameters.Append(objParam)
objParam = objCmd.CreateParameter("@Password",200,1,"100",Session("Password"))
objCmd.Parameters.Append(objParam)

rs.Open objCmd, dbconn, 1, 1

do while not rs.eof ------->here comes error 
    EmailID = rs(0)
    Password =  rs(1)
    'response.Write EmailID & "," & Password & "<br">
    rs.MoveNext
loop

I hope it's not too late!!

Upvotes: 0

Jinesh Jain
Jinesh Jain

Reputation: 1242

try with below code.

SET rs = objCmd.Execute(Session("EmailID"),Session("Password"))

Add SET before rs

Upvotes: 0

Related Questions