小编典典

VBscript和ADO-3704关闭对象时,不允许进行操作

sql

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

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查询时,它可以工作。有人能帮忙吗?


阅读 380

收藏
2021-04-07

共1个答案

小编典典

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

2021-04-07