title: Visual Studio C++ : Debug Assertion Failed
body: <p>I recently tried to create a program that can read an ODBC database then write the entries in an Excel file by using the CRecordset class, the program complilates perfectly, but the problems come in the execution...</p>
  <p>First error :</p>
  <blockquote>
  <p>Debug Assertion Failed!</p>
  <p>Program: C:\Windows\system32\mfc140ud.dll</p>
  <p>File: f:\dd\vctools\vc7libs\ship\atlmfc\include\afxwin1.inl</p>
  <p>Line: 24</p>
  </blockquote>
  <p>Second error :</p>
  <blockquote>
  <p>Debug Assertion Failed!</p>
  <p>Program: C:\Windows\system32\mfc140ud.dll</p>
  <p>File: f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dbcore.cpp</p>
  <p>Line: 3312</p>
  </blockquote>
  <p>The two errors are pointing toward the mfc140ud.dll file, it's not a missing file, so it's not the problem.</p>
  <p>Here is the function where the exception is raised:</p>
  <pre><code>void parseDB(CRecordset &amp;rs, const CString &amp;SqlString, CString strOut) {
  
  std::cout &lt;&lt; &quot;test2&quot;;
  
  rs.Open(CRecordset::snapshot, SqlString, CRecordset::readOnly);
  std::string entry;
  std::fstream file;
  
  std::cout &lt;&lt; &quot;test3&quot;;
  
  while(!rs.IsEOF()) {
  
      std::cout &lt;&lt; &quot;test4&quot;;
      rs.GetFieldValue((short)0, strOut);
      CT2CA pszConvertedAnsiString = strOut; 
      entry = pszConvertedAnsiString;
  
      writeXLSX(entry.c_str(), file);
  
      rs.MoveNext();
  
  }
  
  rs.Close();
  
  }
  </code></pre>
  <p>The &quot;std::cout &lt;&lt; &quot;test&quot;&quot; are here for debugging, and my program generates these errors right after the &quot;test2&quot; display, so I deducted that the error comes from the &quot;Open&quot; line.</p>
  <p>This is the way I initialize the CRecordset:</p>
  <pre><code>CString sDsn;
  CDatabase db;
  CRecordset rs(&amp;db);
  CString strOut;
  CString SqlString;
  </code></pre>
  <p>Then, I use a CALL SQL function in a switch-case:</p>
  <pre><code>switch (sequence) {
          case 1:
              SqlString = &quot;CALL GETCUSNAME(AGENTS)&quot;;
              break;
          case 2:
              SqlString = &quot;CALL GETCUSNAME(CLIENT)&quot;;
              break;
          default:
              AfxMessageBox(_T(&quot;Wrong entry!&quot;));
          }
  </code></pre>
  <p>I searched on many sites and I couldn't find an answer, that's why I ask a question here, thanks by advance.</p>