how to read records from ESE database using cpp

1.2k Views Asked by At

I have open the ESE database successfully by using JetOpenDatabase API. To read the records I have open the "MSysObjects" table and set the current index to the "RootObjects".

Here's my code (without error-handling):

err = ::JetOpenTable(sessionID,dbID,"MSysObjects",NULL,0,0,&tableId);
err = ::JetSetCurrentIndex( sessionID, tableId, "RootObjects" );
err = ::JetMove( sessionID, tableId, JET_MoveFirst, 0 );

to read the records I have tried the JetRetrieveColumns function to retrieves multiple column values from the current record. I have also tried JetRetrievedColumn function but I didn't get the actual result.

Is any one know that how to read the records from existing and unmounted ESE database files by using cpp?

2

There are 2 best solutions below

1
Fotis MC On

The esent engine gives you a hint of what went wrong by the error code. Look it up here: https://msdn.microsoft.com/en-us/library/gg269297(v=exchg.10).aspx

In general you have to prepare the JET_RETRIEVECOLUMN before you do actually try to read the data via JetRetrieveColumn(s), by selecting which columns you want to retrieve, preparing buffer/pointers, etc. Of course there's more to it, but you should be a little bit more specific with your question.

4
Martin Chisholm On

Yes, Fotis gives good advice. The specific error codes are very valuable. Since you're looking for example code, some of the more comprehensive example code is written in C#.

Take a look at the EsentInteropTests at https://managedesent.codeplex.com/SourceControl/latest. Search for RetrieveColumn, and it will give you a good idea on which orders to call in which order. Sure, it's not the right language, but you can easily translate.

I presume you're using MSysObjects as an example because every database has that table. It's for internal use, and can be fairly cryptic to decipher.

-martin