程序中有一function被反复调用,其中一句Set RecordSet=Connection.Execute(...)
在一台机子上执行没有问题,在另一台机子上执行总是在大概第50几次调用的时候说RecordSet不能被用来打开别的表了。不知有谁遇到过这个问题,还望指教

解决方案 »

  1.   

    这样:
    Set RecordSet = New ADODB.RecordSet
    recordset.open  .....
    ....
    recordset.close
    set recordset = nothing
      

  2.   

    '业务员合同
        With Rs_Jc_Shhy_Csb
            If .State = adStateOpen Then
                .Close
            End If
            .ActiveConnection = adoCN
            .CursorLocation = adUseClient
            .CursorType = adOpenDynamic
            .LockType = adLockBatchOptimistic
            .Source = "SELECT * FROM Jc_Shhy_Csb WHERE  hth='" & W_Jc_Shhy.Text1(0).Text & "'"
            .Open
        End With
      

  3.   

    if rs.state=adStateOpen then rs.close
      

  4.   

    在你的rs.open执行之前先执行上述语句
      

  5.   

    qqqdong和lxcc的方法都试过了,不行,而且我的RecordSet定义的是局部变量,在函数执行完一次后应该是自动关闭RecordSet的吧。
      

  6.   

    RecordSet定义的是局部变量,在函数执行完一次后变量是自动关闭,但RecordSet与数据库的连接不会断开,并且RecordSet占用的内存也不会释放。
    RecordSet打开一次,就要关闭一次。
      

  7.   

    那么我程序中应该是已经关闭了RecordSet的吧。那如何解决我的问题呢
      

  8.   

    将局部变量RecordSet换成别的变量名,是不是相互调用时,其它过程中也有RecordSet变量而相互冲突。
      

  9.   

    还是不行,总是报run-time error '-2147467259(80004005)':不能再打开其他表了
    我按出错信息搜索,2147467259对应的是unspecified error
      

  10.   

    以下是msdn对2147467259错误的描述。ERROR NOTES
    Only the ADO Connection object has an errors collection. The observant reader will notice that a lightweight error handler is in effect for the RecordSet.Open examples. In the event of an error opening a RecordSet object, ADO should return the most explicit error from the OLEDB provider. Some common errors that can be encountered with the code above are described below. If you omit (or there is an error in) the DefaultDir parameter in the connect string, you may receive the following error: 
       ADO Error #   -2147467259
       Description   [Microsoft][ODBC Microsoft Access 97 Driver] '(unknown)'
                     isn't a valid path.  Make sure that the path name is
                     spelled correctly and that you are connected to the server
                     on which the file resides.
       Source        Microsoft OLE DB Provider for ODBC Drivers
    If there is an error in the Dbq parameter in the connect string, you may receive the following error:    ADO Error #   -2147467259
       Description   [Microsoft][ODBC Microsoft Access 97 Driver] Couldn't find
                     file '(unknown)'.
       Source        Microsoft OLE DB Provider for ODBC Drivers
    The previously listed errors will also populate the Connection.Errors collection with the following errors:    ADO Error #   -2147467259
       Description   [Microsoft][ODBC Driver Manager] Driver's
                     SQLSetConnectAttr failed
       Source        Microsoft OLE DB Provider for ODBC Drivers   ADO Error #   -2147467259
       Description   Login Failed
       Source        Microsoft OLE DB Provider for ODBC Drivers
    Note that for each error, the ADO Error number is the same, in this case translating to 0x80004005, which is the generic E_FAIL error message. The underlying Component did not have a specific error number for the condition encountered, but useful information was never-the-less raised to ADO. 有可能是connection对象连接时间过长而断开了,试试用字符串而不是用connection

    recordset.open sSQL, sConn
      

  11.   

    感谢limit(梦锦) ,你说的方法似乎是管用的,原先出错的那行已经顺利执行了,但我还有一个问题,就是现在出错的地方变成了下面一处使用到connection对象的地方,
    Set recordset = connection.OpenSchema(...)
    这句中我如何替换掉connection对象呢,因为openschema似乎是connection对象才有的方法
    还望再次指教