如何代码中,是否要注销记录集?
private function fun1(byref rs as recordset,byval strerr as string)
   on error goto errfun1
   ...
   xx=fun2(rs,strerr)
   此处是否需要关闭并释放掉rs?
   (rs.close:set rs=nothing)
   exit function
errfun1:
   if err.number then strerr="error1"
end functionprivate function fun2(byref rs as recordset,byval strerr as string)
   on error goto errfun1
   ...
   此处是否需要关闭并释放掉rs?
   (rs.close:set rs=nothing)
   exit function
errfun1:
   if err.number then strerr="error1"
end function

解决方案 »

  1.   

    在哪里产生,最好在哪里关闭
    如果在调用fun1的函数中定义的rs,如不再需要,最好有在调用fun1的函数中关闭,这样,代码比较明朗
      

  2.   

    建议使用 If rs.State = 1 Then rs.Close 这样来关闭记录集
    先关闭记录集再关闭数据库
    当对象关闭后再释放对象
      

  3.   

    private function fun1(byref rs as recordset,byval strerr as string) 
      on error goto errfun1 
      ... 
      xx=fun2(rs,strerr) 
       
      exit function 
    errfun1: 
      if err.number then strerr="error1" 
    end function private function fun2(byref rs as recordset,byval strerr as string) 
      on error goto errfun1 
      ... 
      rs.open   ...          打开 
      ... 
      
      rs.close   关闭
      set rs=nothing       释放  exit function 
    errfun1: 
      if err.number then strerr="error1" 
         If rs.State = adStateOpen Then rs.Close   '异常时关闭
        If Not rs Is Nothing Then Set rs = Nothing   '异常时释放
    end function