Click here to Skip to main content
15,887,027 members
Articles / Mobile Apps / Windows Mobile

A set of ADOCE classes

Rate me:
Please Sign up or sign in to vote.
4.78/5 (21 votes)
6 Aug 2003CPOL3 min read 555.5K   1.2K   40   312
Porting Carlos Antollini's ADO classes to the Pocket PC.

Sample Image - ado_ce_ca.jpg

Introduction

One of the questions I have seen most frequently asked in Pocket PC development groups, is how to develop in eVC using ADOCE and Pocket Access. There are some resources on the web for this, but it is hard to find a freely available set of C++ classes that will encapsulate ADOCE 3.1 in complete fashion. After looking in CP, I found a very good candidate.

This article presents a port of Carlos Antollini's popular ADO classes to the Pocket PC. Carlos' article (A set of ADO Classes - version 2.07) presents a fairly thorough coverage of desktop ADO and was selected for porting because it is freely available and it is very popular.

The port

The Pocket PC uses ADOCE 3.1, a cut-down version of the ADO implementation found on desktop computers. The ADOCE 3.1 object model is smaller in both number of objects and methods. Nevertheless, it is quite usable for most database applications, retaining its ease of use.

Source compatibility

One of the objectives of this port was to keep source compatibility. Hence, you will be able to compile the source files (ado.h and ado.cpp) in both platforms: Desktop and Pocket PC. The source compatibility was achieved using precompiler directives, which may render some parts of the code harder to read.

What's missing?

Of all of Carlos' classes, the Pocket PC will only see CADODatabase and CADORecordset. In fact, these are the only classes that have direct ADOCE support. Also, not all of the classes' methods are supported and have been removed. Here is a list of the unsupported methods:

  • void CADODatabase::dump_com_error(_com_error &e);
  • BOOL CADORecordset::AddNew(CADORecordBinding &pAdoRecordBinding);
  • BOOL CADORecordset::RecordBinding(CADORecordBinding &pAdoRecordBinding);
  • CString CADORecordset::GetString(LPCTSTR lpCols, LPCTSTR lpRows, LPCTSTR lpNull, long numRows = 0);

Also, there are missing items in the CADORecordset::cadoDataType enumeration.

What's new?

During the port I had to add some missing functionalities, the most important of which is UNICODE support.

During the first debugging session I also found that CADORecordset::Open needed a new mode (openUpdate) to allow for correct use of the Update method (see sample code for an example).

Porting warnings

Check that the #import directive in ado.h is correct for your development environment.

The port has not been thoroughly tested. Please help me with this ongoing process.

Using Pocket Access

Pocket Access is a very simple database manager. It is so simple that it will not support the following (among other) desktop features:

  • Unique indexes
  • Referential integrity
  • Advanced SQL statements (almost everything is missing)
  • Autonum fields

You also have some limitations to note:

  • Maximum number of 4 indexes per table
  • Maximum of 4 tables per JOIN
  • You only get INNER JOINs

So why use it? It is very simple to setup and synchronize with your desktop environment, and you don't have to pay licensing fees.

Using ADOCE to manage your tables may be trickier than you thought, so I prepared a simple demo application that manages (does not delete - yet) a list of authors of this section. The bulk of the work is in CChildView, a CListCtrl-derived class, where records are created and modified. Please do note the peculiarities of adding new records and updating an existing record.

Sample application

The sample application is provided with full source code and with two versions of the database: desktop (.mdb) and Pocket PC (.cdb). You can create the second from the first, by using ActiveSync. If you only have an emulator to play with, you can copy the .cdb file directly into the \My Documents folder.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Frotcom International
Portugal Portugal
I work on R&D for Frotcom International, a company that develops web-based fleet management solutions.

Comments and Discussions

 
GeneralRe: Access Violation Error Pin
Ram Murugan25-Feb-04 14:21
Ram Murugan25-Feb-04 14:21 
GeneralClose() funcion Pin
harmendejong17-Feb-04 4:36
harmendejong17-Feb-04 4:36 
GeneralRe: Close() funcion Pin
Alex Evans18-Apr-04 18:13
Alex Evans18-Apr-04 18:13 
GeneralBugfix - SqlServer CE 2.0 - Opening a recordset in table mode Pin
<marquee>ajh12-Feb-04 13:49
sussajh12-Feb-04 13:49 
GeneralRe: Bugfix - SqlServer CE 2.0 - Opening a recordset in table mode Pin
João Paulo Figueira14-Feb-04 0:33
professionalJoão Paulo Figueira14-Feb-04 0:33 
GeneralSQL CE 2.0 &amp; EVC 4.2 success Pin
<marquee>ajh11-Feb-04 18:01
sussajh11-Feb-04 18:01 
GeneralRe: SQL CE 2.0 &amp; EVC 4.2 success Pin
João Paulo Figueira11-Feb-04 22:04
professionalJoão Paulo Figueira11-Feb-04 22:04 
GeneralLet me also have SQL CE 2.0 &amp; EVC 4.2 success Pin
dharani23-Mar-04 17:20
dharani23-Mar-04 17:20 
Hi ajh and author !!! i am also pulling my hair to make OLE DB to work for my MFC evc++ app . Here is what I want pls help me..
i am a new user on embedded vc++ / SQL Ce. I am yet to find out whether my SQL CE installation is correct or not . To summarise what I did ...
IIS Is already running ....
1) Installed embedded vc++ 4.0
2) Installed pocket PC 2003 SDK
3) Installed SQL Server CE 2.0 ( I think its SP1). My system is XP . I am able to run MFC applications on the emulator . fine.The SQL Server CE installed the folders . D:/program files/ SQL Server CE 2.0 and in that the following folders /Server /Redist /Samples /Inc /Lib etc . In the start menu
I got Start -->prog files-->SQL Server CE --->SQL Server CE connectivty management . I created a virtual folder and the sql server ce agent is (sscesa20.dll) at d:/prog files/SQL Server CE/Server . Ok . But I am trying to connect to SQL Server database from within the emulator and later on with device ( Pocket PC Casio 800 which I have not yet seen ) ...
This is the piece of code I have written the Pocket PC appliation ..
#include "D:\Program Files\Windows CE Tools\wce420\POCKET PC 2003\Include\Emulator\oledb.h"
#include "D:\Program Files\Windows CE Tools\wce420\POCKET PC 2003\Include\Emulator\oledberr.h"
#include "D:\Program Files\Microsoft SQL Server CE 2.0\Inc\ssceoledb2.h"

IDBDataSourceAdmin *pIDBDataSourceAdmin = NULL;

HRESULT hr= NOERROR;
ULONG cProps = 1;
DBPROP rgProps[1];
DBPROPSET PropSet;


// Create the SQL Server CE provider
//
hr = CoCreateInstance(CLSID_SQLSERVERCE_1_0,NULL,CLSCTX_INPROC_SERVER,
IID_IDBDataSourceAdmin,(void**)&pIDBDataSourceAdmin);
//Set the properties

if(SUCCEEDED(hr))
{
AfxMessageBox(_T("done"));
}
else
{
AfxMessageBox(_T("not done"));
}
for (ULONG i = 0; i < cProps; i++ )
{
VariantInit(&rgProps[i].vValue);
rgProps[i].dwOptions = DBPROPOPTIONS_REQUIRED;
rgProps[i].colid = DB_NULLID;
}

rgProps[0].dwPropertyID = DBPROP_INIT_DATASOURCE;
rgProps[0].vValue.vt = VT_BSTR;
rgProps[0].vValue.bstrVal = SysAllocString(OLESTR("\\Northwind.sdf"));

PropSet.rgProperties = rgProps;
PropSet.cProperties = cProps;
PropSet.guidPropertySet = DBPROPSET_DBINIT;

hr = pIDBDataSourceAdmin->CreateDataSource(cProps,&PropSet,NULL,IID_IUnknown,NULL);

if(SUCCEEDED(hr))
{
AfxMessageBox(_T(" done "));
}
else
{
AfxMessageBox(_T("not done"));
}
But the CoCreateInstance() and CreateDataSource () functions both are failing . In fact I have compilation errors and changed the installed ssceoledb.h with another latest sscedoledb.h patch from MS site . Still I could nt find out how to get the functions sucessful . And could u pls tell me how I could acheive the following.
1) The methods and code to access SQL Server database from SQL CE or ADO CE (if u know tell me The diffrence between SQL CE and ADO CE usageD'Oh! | :doh: and even if i need replication or RDA ..most info availabe from MSDN are large and uncompiled Mad | :mad: )
2) How to get a set of data from SQL Server database into the emulator or device and then update the data and reload it back to SQL server .
I found that eVB has more sample and support than evC++ . And if u could provide me with detailed code snippets for accessing db in sql server , replicating it or RDAing it to the emulator or device and updating it locally and reloading it back to sql server db ..it will be very helpful for me ...
with regards and thanks in advance
dharani babu s
GeneralRe: Let me also have SQL CE 2.0 &amp; EVC 4.2 success Pin
João Paulo Figueira23-Mar-04 22:09
professionalJoão Paulo Figueira23-Mar-04 22:09 
GeneralRe: Let me also have SQL CE 2.0 &amp; EVC 4.2 success Pin
dharani24-Mar-04 1:31
dharani24-Mar-04 1:31 
GeneralRe: Let me also have SQL CE 2.0 &amp; EVC 4.2 success Pin
João Paulo Figueira24-Mar-04 4:27
professionalJoão Paulo Figueira24-Mar-04 4:27 
GeneralConvert MDB to CDB Pin
dragomir10-Feb-04 3:54
dragomir10-Feb-04 3:54 
GeneralRe: Convert MDB to CDB Pin
João Paulo Figueira10-Feb-04 4:22
professionalJoão Paulo Figueira10-Feb-04 4:22 
GeneralRe: Convert MDB to CDB Pin
dragomir10-Feb-04 21:10
dragomir10-Feb-04 21:10 
GeneralStill cannot convert MDB to CDB Pin
dragomir13-Feb-04 20:33
dragomir13-Feb-04 20:33 
GeneralRe: Still cannot convert MDB to CDB Pin
dragomir13-Feb-04 22:19
dragomir13-Feb-04 22:19 
GeneralRe: Still cannot convert MDB to CDB Pin
João Paulo Figueira14-Feb-04 0:32
professionalJoão Paulo Figueira14-Feb-04 0:32 
GeneralRe: Still cannot convert MDB to CDB Pin
dragomir15-Feb-04 20:43
dragomir15-Feb-04 20:43 
QuestionHow to use this in Emulator Pin
HydGuy3-Feb-04 23:59
HydGuy3-Feb-04 23:59 
AnswerRe: How to use this in Emulator Pin
João Paulo Figueira4-Feb-04 0:13
professionalJoão Paulo Figueira4-Feb-04 0:13 
QuestionHow to open db file in CF or SD card? Pin
databank8028-Jan-04 17:55
databank8028-Jan-04 17:55 
AnswerRe: How to open db file in CF or SD card? Pin
João Paulo Figueira29-Jan-04 0:47
professionalJoão Paulo Figueira29-Jan-04 0:47 
GeneralCannot open db in EVC4SP2 Pin
databank8028-Jan-04 6:37
databank8028-Jan-04 6:37 
GeneralRe: Cannot open db in EVC4SP2 Pin
João Paulo Figueira28-Jan-04 7:07
professionalJoão Paulo Figueira28-Jan-04 7:07 
GeneralThanks!! Pin
databank8028-Jan-04 8:27
databank8028-Jan-04 8:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.