【发布时间】:2016-05-06 05:09:30
【问题描述】:
我收到错误 - ADODB.Recordset: 对象关闭时不允许操作。使用多表sql语句时。
其他 sql 语句(简单的)我没有收到和错误,我已将 sql 语句复制到查询中,以验证它在 MSSQL 中从打印出的 sql 变量中正常工作 - 它确实返回值。
方法
sql = "SET NOCOUNT ON;SET ANSI_WARNINGS OFF;use dbcheck; " &_
"select year([00080020]) as YEAR, month([00080020]) as MONTH,sum(bytesize/1024/1024/1024) as GBStored, count(distinct [0020000d]) " &_
" as FinalCount from tblt t, tbls s, tblf f where" &_
" id1 = _id1 and id2 = _id2file" &_
" and [00080020] is not null" &_
" group by year([00080020]), month([00080020]) order by year([00080020]) desc, month([00080020]) desc"
Dim cndb : Set cndb = CreateObject("ADODB.Connection")
Dim rsdb: Set rsdb = CreateObject("ADODB.Recordset")
cndb.Provider = "sqloledb"
cndb.Properties("Data Source").Value = "127.0.0.1"
cndb.Properties("Initial Catalog").Value = "master"
cndb.Properties("Integrated Security").Value = "SSPI"
cndb.CursorLocation = 3
cndb.Open
set rsdb = CreateObject ("ADODB.Recordset")
cmd.ActiveConnection = cndb
cmd.CommandType = 1
cmd.CommandText = sql
rsdb.CursorLocation = 3
rsdb.CursorType = 3
rsdb.LockType = 3
Set rsdb = cmd.Execute
IF Not (rsdb IS Nothing) Then
rsdb.MoveFirst ** ERRORS OUT HERE
谢谢 --------第二次尝试sql是一样的
Dim cndb : Set cndb = CreateObject("ADODB.Connection")
Dim rsdb: Set rsdb = CreateObject("ADODB.Recordset")
cndb.Provider = "sqloledb"
' Set SQLOLEDB connection properties.
cndb.Properties("Data Source").Value = "127.0.0.1"
cndb.Properties("Initial Catalog").Value = "master"
' Windows NT authentication.
cndb.Properties("Integrated Security").Value = "SSPI"
cndb.CommandTimeout=900
cndb.CursorLocation = 3
cndb.Open
rsdb.CursorLocation = 3
rsdb.CursorType = 3
rsdb.LockType = 3
rsdb.Open sql,cndb
rptFile.WriteLine sql
rptFile.WriteLine cndb.State
rptFile.WriteLine rsdb.State
IF Not (rsdb IS Nothing) Then
If Not rsdb.EOF Then * Errors out on this line
rsdb.MoveFirst
【问题讨论】:
-
你试过 rsb.open 吗?
-
不应该将
ActiveConnection设置为设置,因为它是一个对象引用?Set cmd.ActiveConnection = cndb -
那里有很多阅读材料,而这只是我回答的那些。
标签: sql-server vbscript adodb