I have the exact problem with the exact error message.
Here is my excel macro code:
Sub Test() Dim RangeA As Range Dim RangeB As Range
Set RangeA = Worksheets("CS").Range("B3") Set RangeB = Worksheets("CS").Range("G3")
Dim conn As New ADODB.Connection Dim rst As New ADODB.Recordset Dim stConn As String Dim i As Integer, j As Integer
stConn = "Server=MyPc;Database=XXXX;uid=xxxx;pwd=xxxx" With conn .Provider = "SQLOLEDB" .ConnectionString = stConn .Open If conn.State = ADODB.adStateOpen Then Set rst = conn.Execute(proc_Test @Start='" & CDate(RangeA.Value) & _ "'" & ", " & "@End='" & CDate(RangeB.Value) & "'") j = 5 While Not (rst.BOF Or rst.EOF) For i = 0 To rst.Fields.Count - 1 ActiveSheet.Cells(j, i + 1).Value = rst.Fields(i).Value Next j = j + 1 rst.MoveNext Wend rst.Close conn.Close End If End With
Set conn = nothing Set rst = nothing
End Sub
The yellow highlight is where it crashed with that error message. I ran that sproc in QA and it worked. My sproc had two select statement. The 1st select queries against multiple tables using inner join and few aggregate functions. Then the result is "fetch" into a temporary table (@Tb) created inside the sproc. This is local temp table. Last 2nd select queries against this temp table. I have even tried to use global temp table (##Tb) yet it still crashed.
I knew the exec statement in my macro did run successfully because I ran a simple select statement against the global temp table when I stepped thru my code. That's how I find out the status.
I have tried to use "Trusted Connection = yes" and "Integrated Security = SSPI" for my connection, it makes no diff. Can anyone shed some light on how I can fix this? Thank you in advance. |