ADO错误“未指定的错误”; SQL Server没有错误

我在Excel 2007 VBA中使用ADO从SQL Server返回数据。 我使用Union All汇总了大量的Select语句。

对于多达110个汇总Select语句,它工作正常,但是在115个语句中,我得到ADO错误“未指定的错误”。 在110 Select语句中,它返回大约7,000行和255列,所以它不是一个exception大的ADOlogging集。

我认为ADO可能是从SQL Server传递错误,就像Excel VBA从ADO传递它(我知道错误是从ADO,而不是VBA,因为错误显示在ADO连接对象的错误集合中),所以我将带有115个Select语句的问题SQL语句发送给拥有所查询的SQL Server数据库的同事,询问她是否可以告诉我SQL Server不喜欢什么。 但是,它在SQL Server查询工具中运行良好,并返回了预期的数据。

所以看起来只是ADO不喜欢它,当我去115select语句; SQL Server数据库本身就很好。

顺便说一句,我还没有testing111 – 114select语句; 我只是把它缩小到110和115打破。

任何想法可能是什么,我能做些什么呢?

现在我要把它分成50个Select语句集作为解决方法,但是如果可以一次发送它,我想。

以下是相关的代码:

Public Const SQL_UNION_ALL_OPERATOR As String = " UNION ALL " (the loop that aggregates the Select statements starts here) stSQL = _ "select * from LikeItemExtract" & _ " where Dept = " & varLikeDept & "" & _ " and sup_name = '" & varLikeSupp & "'" & _ " and VPN = '" & varLikeVPN & "'" & _ " and Loc_Key = " & varCADLoc & "" & _ " and SUPP_COLOR = '" & varLikeColor & "'" stSQLAll = stSQLAll & stSQL & SQL_UNION_ALL_OPERATOR (end loop here) 'remove the final " UNION ALL ": If Right(stSQLAll, Len(SQL_UNION_ALL_OPERATOR)) = SQL_UNION_ALL_OPERATOR Then stSQLAll = Left(stSQLAll, Len(stSQLAll) - Len(SQL_UNION_ALL_OPERATOR)) End If If CBool(rs1.State And adStateOpen) = True Then rs1.Close rs1.Open stSQLAll, con, adOpenStatic, adLockReadOnly, adCmdText iRecordsetRowCount = shAggData.Cells(1).CopyFromRecordset(rs1) 

谢谢,

格雷格