PRB: MFC DAO Classes Error "Syntax Error in From Clause" or Assertion in Daocore.cpp, Line 4854

ID: Q238436


The information in this article applies to:
  • Microsoft Visual C++, 32-bit Editions, version 6.0


SYMPTOMS

In the debug version of your MFC DAO application, you may get an assertion in the Daocore.cpp file, line 4854, followed by one of the following error messages:

Syntax Error in From Clause
-or-
The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
This problem happens only if you open a dynaset or snapshot type of CDaoRecordset object and its SQL select statement has a space before it.


CAUSE

The source of this problem is in the MFC CDaoRecordset::Open function located in Daocore.cpp. This function tries to sense the nature of the SQL statement passed to it by scanning for the keyword "SELECT" at line 3345 in Daocore.cpp. If you place a space before the select statement, this code doesn't successfully predict the type of SQL statement, and therefore fails.


RESOLUTION

Remove the preceding space from your SQL select statement.


STATUS

This behavior is by design.


MORE INFORMATION

To reproduce the problem, create a simple dialog-based MFC application. Add a command button to the dialog box and in the handler for this button, add the following code:


CDaoDatabase db;
db.Open("d:\\nwind2.mdb");
CDaoRecordset rs(&db);
rs.Open(dbOpenDynaset, " SELECT * from employees"); //Note the space before the select statement.
while (!rs.IsEOF())
{
	rs.MoveNext();
} 
Compile and run this application. By clicking the created button, you will see an assertion followed by one of the error messages in the Summary section. For an AppWizard-generated CDaoRecordset-derived class, the error message is:
Syntax Error in From Clause
For a nonderived CDaoRecordset class, the error is:
The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.

Additional query words:

Keywords : kbDAO kbDatabase kbMFC kbVC kbVC600 kbGrpVCDB kbDSupport
Version : winnt:6.0
Platform : winnt
Issue type : kbprb


Last Reviewed: October 14, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.