Disconnected Recordsets

Results 1 to 3 of 3

Thread: Disconnected Recordsets

  1. #1
    Join Date
    Dec 1969

    Default Disconnected Recordsets

    &#060;&#037;<BR>Function GetRs(strSql)<BR><BR>&#039;Declare our variables<BR>Dim oConn<BR>Dim oRs<BR>Dim strConn<BR>Dim rs<BR><BR>strconn = "Driver={Microsoft ODBC for Oracle};" & _<BR> "Server=mySvr;" &_<BR> "Uid=developer;" & _<BR> "Pwd=developer12345;" <BR><BR><BR>&#039;Open a connection to the database<BR>set oConn = Server.CreateObject("ADODB.Connection")<BR>oConn.o pen strConn<BR><BR>&#039;Create the recordset object<BR>set oRs = Server.CreateObject("ADODB.Recordset")<BR>oRs.Curs orLocation = adUseClient<BR><BR>&#039;Populate recordset object with a sql query<BR>oRs.open strSql,oConn,adOpenStatic, adLockBatchOptimistic,adCmdText<BR><BR>&#039;Retur n the recordset<BR>Set GetRs = oRs<BR><BR>&#039;Disconnect the recordset<BR>oRs.ActiveConnection = Nothing<BR><BR><BR><BR>&#039;Clean up<BR>oConn.close<BR>oRs.close<BR><BR>set oConn = Nothing<BR>set oRs = Nothing<BR>End Function<BR><BR>&#037;&#062;<BR><BR>&#060;&#037;<B R> &#039; call the function<BR> strSql = "Select AvZone from AvPickMapSetup where" &_<BR> " DataAreaId = &#039;835&#039;"<BR> Set Rs = Server.CreateObject("ADODB.Recordset")<BR> set rs = getrs(strSql)<BR> <BR> <BR> while not rs.EOF <BR> response.write objFlds.Fields("AvZone") <BR> rs.Movenext<BR> Wend<BR> <BR> <BR>&#037;&#062;<BR><BR>with reference to the code, which i learnt from the this site article, i can get it to run through my recordset. I keep getting the error "Operation is not allowed when recordset is closed&#039;.<BR><BR>What have i done wrong?

  2. #2
    Join Date
    Dec 1969

    Default RE: Disconnected Recordsets

    See if this helps<BR>http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=107

  3. #3
    Join Date
    Dec 1969

    Default Don't close the recordset in the function...

    &#039;Clean up <BR>oConn.close <BR>&#039; oRs.close &#060;= Remove this line<BR><BR>The function GetRs returns a pointer to the recordset, not a copy of it. When you close it in the function, you are closing the original.<BR><BR>Take the line out and it should work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts