I'm trying to declare a cursor in ASP using VBScript for a MSSQL database. The code sequence is...

SQLString = "DECLARE @SSQAvg numeric"
ptrSurvey = SQLQuery(cnnDB, SQLString)
SQLString = "DECLARE curSurvey CURSOR FOR SELECT SSQAvg FROM tblSurvey WHERE uid = '" & SurvDat("uid") & "'"
ptrSurvey = SQLQuery(cnnDB, SQLString)
SQLString = "OPEN curSurvey"
ptrSurvey = SQLQuery(cnnDB, SQLString)

I go through a function called SQLQuery(cnnDB,SQLString) that performs the following...

Function SQLQuery(cnnDB, queryStr)
Dim adoRec
Set adoRec = Server.CreateObject("ADODB.Recordset")
adoRec.ActiveConnection = cnnDB
adoRec.Open(queryStr)
Set SQLQuery = adoRec
If Err.Number <> 0 Then
Call TrapError(Err.Number, Err.Description, Err.Source)
End If
End Function

...and the cnnDB function called is:
' Create and open the database connection and save it as a session variable
Set cnnDB = Server.CreateObject("ADODB.Connection")
cnnDB.Open(strConn)
Set CreateCon = cnnDB
If Err.Number <> 0 Then
Call TrapError(Err.Number, Err.Description, Err.Source)
End If

(the variable "strConn" is the standard SQL connection string, and is working on all other db accesses)

However, I keep getting the error:
Number: -2147217900 (0x80040E14)
Source: Microsoft OLE DB Provider for ODBC Drivers
Description: [Microsoft][ODBC SQL Server Driver][SQL Server]A cursor with the name 'curSurvey' does not exist.

...from the Error Trap element when it tries to execute the Open action.


I've taken the raw SQL commands ("SQLString" statements) and put them into the Query Analyzer and they run OK.

What am I doing wrong?

Thanks!

Dnd