Discussion:
C++ ODBC conduit
(too old to reply)
Clinton
2004-01-06 03:52:33 UTC
Permalink
I'm using a C++ conduit to retrieve some databases from the palm and
then push that data into a SQL Server DB. I've got the first part
working fine but don't know where to go with the connection to the SQL
DB.

I want to use ODBC, I'm sure someone has does this before I just need
to get started by knowing what headers to include.

thanks
Baxter
2004-01-06 15:57:48 UTC
Permalink
If you're using Visual C++/MFC, look at the CDatabase/CRecorset classes. An
alternative is to look at ADO. MSDN should contain enough information about
your Connect string.

--
-------------------------------------------------------------------------
Free software - Baxter Codeworks www.baxcode.com
-------------------------------------------------------------------------
Post by Clinton
I'm using a C++ conduit to retrieve some databases from the palm and
then push that data into a SQL Server DB. I've got the first part
working fine but don't know where to go with the connection to the SQL
DB.
I want to use ODBC, I'm sure someone has does this before I just need
to get started by knowing what headers to include.
thanks
Clinton
2004-01-06 22:46:17 UTC
Permalink
Thanks for the quick response Baxter.

Yeah I'm using Visual C++ 6, I've never used it before and this is my
first MFC type program, what headers should I include? I get all sorts
of compiler errors and warnings if I include afxdb.h

I've used ADO in scripting previously and the client would definitely
prefer ODBC. All the MSDN stuff seems to attack the next step about
making the connection etc. But I can't make a connection if I keep
getting undeclared identifiers for any CDatabase calls.(because I
haven't included the correct header).

C.
Post by Baxter
If you're using Visual C++/MFC, look at the CDatabase/CRecorset classes. An
alternative is to look at ADO. MSDN should contain enough information about
your Connect string.
--
-------------------------------------------------------------------------
Free software - Baxter Codeworks www.baxcode.com
-------------------------------------------------------------------------
Post by Clinton
I'm using a C++ conduit to retrieve some databases from the palm and
then push that data into a SQL Server DB. I've got the first part
working fine but don't know where to go with the connection to the SQL
DB.
I want to use ODBC, I'm sure someone has does this before I just need
to get started by knowing what headers to include.
thanks
Clinton
2004-01-07 03:22:52 UTC
Permalink
Ok to get the afxdb.h into a palm conduit I had to start a new one
using the VC++ wizard. This time I created an MFC based DLL. I can now
create objects of type CDatabase, which should now allow me to
communicate with the database.

My problem now is that I don't quite understand the usage of this
conduit structure. Do I now have to create a new class to implement
CBaseMonitor even if I don't want to use it?

Basically my program has some data on the palm which it needs to store
in the ODBC database. After finishing that I want to perform some
queries on the ODBC database and put some data onto the palm... there
is no syncronisation, just an exchange of data. Can anyone see an
easier way of doing this?

Clinton
Baxter
2004-01-07 16:44:59 UTC
Permalink
I found the "MFC based DLL" to be too confusing, and/or not appropriate to
what I needed to do. I stripped out all but the basic Conduit entry points,
and then just wrote my own classes (except for the standard MFC Database and
utility classes (like CString, and CDialog (for configuration)). I don't
use CBaseMonitor or any of the Palm-supplied classes as they just don't work
like I need them to.

My Conduit entry point looks like this:
--------
ExportFunc long OpenConduit(PROGRESSFN pFn, CSyncProperties& rProps)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());

long retval = -1;

if (pFn)
{
CONDHANDLE conduitHandle = (CONDHANDLE)0;
file://Activity syncFinishCode = slSyncFinished;

// If the conduit is set to do nothing, then make a note of it and
return.
if (rProps.m_SyncType == eDoNothing) {
LogAddEntry( "BioCruise - sync configured to Do Nothing.", slText,
false );
return 0;
}

// Register this conduit with SyncMgrDLL for communication to HH
retval = SyncRegisterConduit(conduitHandle);
if (retval) {
LogAddEntry("BioCruise - Unable to register conduit.", slText,
FALSE);
return (retval);
}

// Notify the log that a sync is about to begin
LogAddEntry("", slSyncStarted, FALSE);

// get name of database using conduitDll registry prefs
CDaoDatabase LocalDB;

CString dbName;
dbName = conduitDll.GetProfileString(_T("BioCruise"),
_T("CurrDBName"), NULL);
if (dbName.IsEmpty()) { // slText
LogAddEntry("BioCruise - No Target database - ", slText, FALSE);
retval = -1;
}
else {
try {
// returns 0 if user cancels, but we don't allow connect dialog
// so it will either succeed or throw an exception
LocalDB.Open(LPCSTR(dbName)); // allow shared access
if (!IsValidVersion(&LocalDB)) {
LogAddEntry("BioCruise - Invalid Version of TargetDB",
slSyncAborted, FALSE);
retval = -1;
}
else {
retval = CopyTablesFromHH(&LocalDB); // theRemoteDatabase );
if (!retval) {
LogAddEntry("BioCruise - from HH", slSyncFinished, FALSE);
retval = CopyTablesToHH(&LocalDB); // theRemoteDatabase );
if (!retval) // if success
LogAddEntry("BioCruise - to HH ", slSyncFinished,
FALSE);
}
if (retval)
LogAddEntry("BioCruise", slSyncAborted, FALSE);
}
}
catch (CDaoException* pEx) {
LogAddEntry("BioCruise - Unable to open TargetDB - ",
slSyncAborted, FALSE);
retval = -1;
pEx->Delete();
}
catch(char * str) {
CString msg;
msg.Format("BioCruise - Error on table: %s", str);
LogAddEntry(LPCSTR(msg), slSyncAborted, FALSE);
retval = -1;
}
if (LocalDB.IsOpen())
LocalDB.Close();
AfxDaoTerm();
}

SyncUnRegisterConduit(conduitHandle);
}
return (retval);
}

Note that I'm using CDaoDatabase and not CDatabase. CDaoDatabase is NOT
supported in the newer compilers and MS plans to drop support for DAO.

The CopyTablesToHH() function simply declares a CRecordset (actually
CDaoRecorset) class, opens it, and then copies the data to the appropriate
Palm table record by record. The CopyTablesFromHH() does the reverse.

--
-------------------------------------------------------------------------
Free software - Baxter Codeworks www.baxcode.com
-------------------------------------------------------------------------
Post by Clinton
Ok to get the afxdb.h into a palm conduit I had to start a new one
using the VC++ wizard. This time I created an MFC based DLL. I can now
create objects of type CDatabase, which should now allow me to
communicate with the database.
My problem now is that I don't quite understand the usage of this
conduit structure. Do I now have to create a new class to implement
CBaseMonitor even if I don't want to use it?
Basically my program has some data on the palm which it needs to store
in the ODBC database. After finishing that I want to perform some
queries on the ODBC database and put some data onto the palm... there
is no syncronisation, just an exchange of data. Can anyone see an
easier way of doing this?
Clinton
Loading...