VBscript和ADO-3704关闭对象时,不允许进行操作 [英] VBscript and ADO - 3704 Operation is not allowed when the object is closed

查看:89
本文介绍了VBscript和ADO-3704关闭对象时,不允许进行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此函数在SQL数据库中插入一行,并需要返回创建的标识号:

This function inserts a row into a SQL database and needs to return the identity number created:

Function WriteDatabase(backupTypeID, numImages, folderSize, success, errorMessage, strLogFileName)

    On Error Resume Next
    err.clear
    Set objConnection = CreateObject("ADODB.Connection")
    Set objRecordSet = CreateObject("ADODB.Recordset")
    objConnection.Open "Provider=SQLOLEDB;Data Source=x.x.x.x;Initial Catalog=DB;User ID=sa;Password=xxxxxx"
    sqlquery = "INSERT INTO tblImageCopies (BackupCopyDate, BackupCopyTypeID, NumImages, ImagesFolderSize, Success, ErrorMessage) VALUES (GETDATE(), " & backupTypeID & ", " & numImages & ", " & folderSize & ", " & success & ", " & errorMessage & "); SELECT scope_identity() AS ImageCopyID;" 
    objRecordSet.Open sqlquery,objConnection
    objRecordSet.MoveFirst
    WriteDatabase = objRecordSet("ImageCopyID")
    objRecordSet.Close
    objConnection.Close
    If err.number <> 0 Then
        WriteLog "Error writing to the EHN database - " & err.number & " " & err.description, strLogFileName
    End If

End Function

它成功地插入了行,但是当它尝试返回记录集中的标识号时,出现错误消息 3704,关闭对象时不允许操作。当我直接在服务器上执行此sql查询时,它可以工作。有人能帮忙吗?

It successfully inserts the row, but I get the error message '3704 Operation is not allowed when the object is closed.' when it tries to return the identity number in the record set. When I execute this sql query directly on the server, it works. Anyone able to help?

推荐答案

我做同样的事情(无论如何都很相似)。我相信会有两套结果返回,一套用于INSERT,另一套用于SELECT。尝试调用objRecordSet.NextRecordset()。

I do the same thing (very similar anyway). I believe that there are two sets of results coming back, one for the INSERT and then another for the SELECT. Try calling objRecordSet.NextRecordset().

这篇关于VBscript和ADO-3704关闭对象时,不允许进行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆