tags:

views:

345

answers:

1

I'm trying to execute a stored procedure on SQL Server from an MFC based C++ program. The stored procedure does get executed properly, but an exception is thrown in my program, a CDBException with a message of "Function sequence error". Tracing through the MFC source code for CRecordset::Open, the exception is thrown from MoveNext - this makes sense, as my stored procedure isn't generating any output.

I have both input and output parameters to the stored procedure, so I can't use CDatabase::ExecuteSQL as suggested in this question: http://stackoverflow.com/questions/839739/with-cdatabase-can-i-send-sql-without-using-crecordset

A: 

I finally came up with a hack to fix the problem, I couldn't wait for S.O. to provide an answer. I had already traced the problem to CRecordSet::MoveNext, which immediately calls CRecordset::Move. What I didn't immediately realize is that Move is declared virtual, so it's possible to bypass it with my own version.

void CMyRecordset::Move(long nRows, WORD wFetchType)
{
    (void) nRows;
    (void) wFetchType;
    m_bEOF = true;
}
Mark Ransom