I\'m at a loss on how I can return a readable recordset from a function in classic ASP.
This is what I came up with, but it\'s not working:
Response.
Here's a function that returns a disconnected recordset
Function RunSQLReturnRS(sqlstmt, params())
On Error Resume next
''//Create the ADO objects
Dim rs , cmd
Set rs = server.createobject("ADODB.Recordset")
Set cmd = server.createobject("ADODB.Command")
''//Init the ADO objects & the stored proc parameters
cmd.ActiveConnection = GetConnectionString()
cmd.CommandText = sqlstmt
cmd.CommandType = adCmdText
cmd.CommandTimeout = 900
''// propietary function that put params in the cmd
collectParams cmd, params
''//Execute the query for readonly
rs.CursorLocation = adUseClient
rs.Open cmd, , adOpenForwardOnly, adLockReadOnly
If err.number > 0 then
BuildErrorMessage()
exit function
end if
''// Disconnect the recordset
Set cmd.ActiveConnection = Nothing
Set cmd = Nothing
Set rs.ActiveConnection = Nothing
''// Return the resultant recordset
Set RunSQLReturnRS = rs
End Function
Well, you are closing the recordset and connection immediately after setting the function's return variable, so that explains the error messages.
I am not a VB developer, but I think what you need to look at is Disconnected Recordsets. Take a look at this article, it's doing pretty much exactly what you want.