views:

266

answers:

2

Hi I keep getting the error:

Error (3709) - /mysite/Pages_Secure/mypage.asp ADODB.Recordset.

"The connection cannot be used to perform this operation. It is either closed or invalid in this context.."

strQuery = ""
strQuery = strQuery + "SET ROWCOUNT 0 "
strQuery = strQuery + "SELECT FIRSTNAME, LASTNAME, EMAIL, USER_TEAM_ID, USER_SERVICE_ID, USER_DIRECTORATE_ID "
strQuery = strQuery + "FROM Web_Users "
strQuery = strQuery + "WHERE USER_ID = '" + Cstr(lOwnerID) + "'"

CALL subOpenConnection("", "")

Set RS = Server.CreateObject("ADODB.RecordSet")

RS.Open strQuery, objDBConnection

Error happens here after the open....

SUB subOpenConnection( strErrorPage, strErrorQueryArguments )

 Set objDBConnection = Server.CreateObject("ADODB.Connection")

 objDBConnection.ConnectionTimeout = Application("ConnectionTimeout")
 objDBConnection.CommandTimeout = Application("CommandTimeout")
 objDBConnection.CursorLocation = Application("CursorLocation")
    objDBConnection.Open Application("ConnectionString") 

END SUB

Any ideas?

A: 

I think it's because you're using SUB rather than FUNCTION. The sub won't return the connection object (which is why you get an error that it's closed), whereas a function can return the connection object. Does this sub work anywhere else? Or is this the only time it's used?

fortheworld
that's the thing, it is used elsewere....
thegunner
The only other thing i could think of is removing the set rowcount from the SQL string because i would normally be running something like that within a stored proc. I've always thought that ADO wouldn't be able to do anything more than 1 statement per recordset.
fortheworld
A: 

ok managed to get this working...can't quite remember how - but was something i had missed! D'oh!

thegunner