2008年3月20日星期四

20.03.2008 Aufgabe: Exclusiv Connection Access DB with Ado

1. Korrektur von Access Dantenbank verbindung mit Ado.Um Exception von DB_Close() zu überwinden,vor "if ( m_pADOpaelogbuch->bConnectionIsOpen() )" addiere "if (m_pADOpaelogbuch != NULL)", erst prüft mal die Abwesenheit der Pointobjekte "m_pADOpaelogbuch":

if (m_pADOpaelogbuch != NULL)
{

if ( m_pADOpaelogbuch->bConnectionIsOpen() )
{

if( m_pADOpaelogbuch->CloseRecordsetAdoDB() ||
m_pADOpaelogbuch->CloseConnections() )
{

delete m_pADOpaelogbuch;
m_pADOpaelogbuch = NULL;
error = NOT_ERROR;

}
else
{
error = ADO_DISCONNECT_ERROR;

}

}else
{
AddStringError((LPCTSTR)(CString("connect from paelogbuch to ") + plc.tgDB + CString(" has not been opend.")) );
error = ADO_CONNECT_ERROR;
}

}


2. Bei DB_Open():

if (!( m_pADOpaelogbuch = new ADOpaelogbuch((LPCTSTR)plc.tgDB) ))
{

error = ADO_CONNECT_ERROR;

}

ist "if (!( m_pADOpaelogbuch = new ADOpaelogbuch((LPCTSTR)plc.tgDB) ))" ungültig, weil "ADOpaelogbuch(tgDB)" kein returned Value.
Codes:

//////////////////////////////////////////////////////////////////////
// *
// * Editor: zengzn@gmail.com 20.03.2008
// * after testing is known, that "CAdoExternDB *m_pExternDB;"
// * makes m_pExternDB not NULL, exceptions will only been thrown by
// * "m_pExternDB->bConnectionIsOpen()" if "new CAdoExternDB((LPCTSTR)sDB,nMode)"
// * tries to connect a unexsiting file.
// * It does not matter if the exlusive connection fails
// * or opens a wrong file(.txt or others), no exception throws out.
// *
//////////////////////////////////////////////////////////////////////
if (plc.existFile(sDB))
{

m_pExternDB = new CAdoExternDB( (LPCTSTR)sDB, nMode );
if (m_pExternDB != NULL)
{

if (m_pExternDB->bConnectionIsOpen() )

error = NOT_ERROR;

else

error = ADO_CONNECT_ERROR;


}
else

error = ADO_CONNECT_ERROR;


}
else
{

error = OPEN_FILE_FAILED;

}

3. Exclusive connection to Access DB with Ado:
in ADOBase.cpp:

OpenAdoDB(AdoNs::_ConnectionPtr& pConnDB, const char* sDatabasePath, AdoNs::ConnectModeEnum nMode)
...
pConnDB->Mode = nMode;

nMode can be:

msado15.tlh
enum ConnectModeEnum
{

adModeUnknown = 0,
adModeRead = 1,
adModeWrite = 2,
adModeReadWrite = 3,
adModeShareDenyRead = 4,
adModeShareDenyWrite = 8,
adModeShareExclusive = 12,
adModeShareDenyNone = 16,
adModeRecursive = 4194304

};


4. Versuche die Möglichkeit die DB Einspielung mit ADO-Exclusive Connection,wenn andere Client verbindung nach DB-Server hat, warte mal kurz(1 min ? ) und versucht nochmal, sonst "adModeUnknown" und alert den Benutzer ob weiter geht.

没有评论: