gpt4 book ai didi

sql - VBscript 和 ADO - 3704 对象关闭时不允许操作

转载 作者:太空狗 更新时间:2023-10-30 01:53:26 48 4
gpt4 key购买 nike

此函数向 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 查询时,它起作用了。有谁能帮忙吗?

最佳答案

我做同样的事情(反正非常相似)。我相信有两组结果返回,一组用于 INSERT,另一组用于 SELECT。尝试调用 objRecordSet.NextRecordset()。

关于sql - VBscript 和 ADO - 3704 对象关闭时不允许操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1712094/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com