Debug Assertion Failed Expression: GetInterface()!=0 error when writing to database table

StackOverflow https://stackoverflow.com/questions/22443303

  •  15-06-2023
  •  | 
  •  

Question

Im working on a MFC project which communicates specific table on my SQL Server. But when I try to make delete query I get Debug Assertion Failed error message at runtime and also nothing is deleted when I check my table. This is the code where I think the error is:

<pre> HRESULT hr;
    hr=COLEDBTESTSetAccessor::OpenDataSource();
    if(FAILED(hr))
        MessageBox(NULL,"Connection Failed\n","",MB_OK);
    else
        MessageBox(NULL,"Connected\n","",MB_OK);
    CString strString;
    strString.Append("DELETE FROM PHONE_NUMBERS WHERE ID=");
    CString strParam;
    strParam.Format("%d",nId);
    strString.Append(strParam);
    MessageBox(NULL,(LPCSTR)strString,"",MB_OK);
    hr=this->Open(m_session,strString); <code>

The same also happens with Update and Insert Query but the table records are updated. Can anyone tell me where is my mistake? Thank you. :)

Was it helpful?

Solution

I can not see from what base class you derive you class. I assume you have a Command object.

So what happens is that you already performed an operation with an Open call. But after an open you need a Close operation before you can use the command again with a new statement and Open operation.

Look at the m_spCommand member.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top