ADO Recordset->EndOfFile giving me _com_error when Empty Recordset

三世轮回 提交于 2019-12-31 04:47:21

问题


I'm using ADO, and getting a very weird com error.

So I'm simply running a stored proc using ADO CommandPtr, and storing it in a Recordset.

Here is what I'm doing:

_ConnectionPtr Connptr;
//Instantiate ConnectionPtr...

_CommapndPtr CommPtr;
CommPtr.CreateInstance(__uuidof(Command));
CommPtr->CommandType = adCmdText;
CommPtr->ActiveConnection = ConnPtr;
CommPtr->CommandText = "Execute MyDb..MyStoredProc";

_RecordsetPtr RecPtr;
RecPtr.CreateInstance(__uuidof(Recordset));
RecPtr->CursorLocation = adUseClient;
RecPtr->CacheSize = 150;

RecPtr = CommPtr->Execute(NULL, NULL, adOptionUnspecified);   //RecPtr = Empty Recordset

while (!RecPtr->EndOfFile) {       //ERROR HAPPENS HERE!!!
    //Do something
    RecPtr->MoveNext();
}

So my stored procedure is supposed to returns an empty recordset (0 rows).

But then , when I check if the recordset has reached the end (which should simply return true if it is empty). I get a com error.

When I caught the com error and printed it out, I got this.

Code = -2147217849
Meaning = IDispatch error #3153
Source = NULL

Which doesn't tell me much.

I don't understand why RecPtr->EndofFile is throwing a com error, since it should simply return true/false.

I highly doubt that the error is caused because I'm doing something wrong when initializing Connection and Command objects. (If so, then I would have gotten the error when Executing the command.)

Any ideas on what might be causing this exception?

来源:https://stackoverflow.com/questions/25017995/ado-recordset-endoffile-giving-me-com-error-when-empty-recordset

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!