Problem : ADO recordSet.RecordCount Property not working with Stored Procedure
I am using ADO in Excel 2003 to connect to a SQL Server 2005 Express DB. Upon moving my application’s SQL statements to stored procedures, my recordSet.recordCount property isn’t working anymore. Does ADO work differently for stored procedures than raw SQL? I was under the impression that it just passed the text to the database to be parsed and retuned the desired recordset. Is there a parameter I am missing or have wrong? I get my data results back, so it is reaching the database correctly… I am stumped.
What I have:
Public Sub executeQueryToRange(someSQL As String, aRange As Range, recordSet As ADODB.recordSet)
‘Lets the error logger know where the error came from
Const Source As String = “executeQueryToRange()”
‘ Check the connection to the database is still active
If Not DataConn.checkDBConnection() Then Err.Raise HANDLED_ERROR
‘Execute the query on the database
recordSet.Open someSQL, DataConn.getConnection, adOpenStatic, adLockReadOnly, adCmdText
‘If we get results, then print them at the given offset, if not throw an exception and log it
If Not recordSet.EOF Then
Err.Raise QUERY_ERROR, Source, _
“Error retrieving data. Attempted Query: ” & someSQL
Thanks in advance for any help.
Solution: ADO recordSet.RecordCount Property not working with Stored Procedure
Use adCmdStoredProc instead of adCmdText, if you are calling a stored procedure.