IBM DB2 incorrect ErrorCode

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
WaveRunner
Posts: 4
Joined: Wed 17 Nov 2021 17:04

IBM DB2 incorrect ErrorCode

Post by WaveRunner » Thu 18 Nov 2021 09:05

Hi,

I'm using UniDac Components v.7.4.12 with IBM DB2 Database. My problem is that I can't get the right ErrorCode value. For example, if I try to insert duplicate row in DB and then get the ErrorCode, it always will be -1:

Code: Select all

try
{
    ...
}
catch(EDAError& E)
{
    DbErrorCode = E->ErrorCode; // or DbErrorCode = EUniError(E).InnerError->ErrorCode;
}
Although, according to error codes list, the ErrorCode value should be -803. Can anybody help me with that problem?

Thanks

WaveRunner
Posts: 4
Joined: Wed 17 Nov 2021 17:04

Re: IBM DB2 incorrect ErrorCode

Post by WaveRunner » Wed 24 Nov 2021 10:31

I still need help

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: IBM DB2 incorrect ErrorCode

Post by MaximG » Fri 26 Nov 2021 14:30

Please try to verify the described behavior using the latest version UniDAC 9.0.1

WaveRunner
Posts: 4
Joined: Wed 17 Nov 2021 17:04

Re: IBM DB2 incorrect ErrorCode

Post by WaveRunner » Fri 26 Nov 2021 14:49

MaximG wrote: Fri 26 Nov 2021 14:30 Please try to verify the described behavior using the latest version UniDAC 9.0.1
I'm working in BCB6. As I suppose v9.0.1 is for RAD 11 Alexandria

Gunmannn
Posts: 1
Joined: Mon 29 Nov 2021 16:43

Re: IBM DB2 incorrect ErrorCode

Post by Gunmannn » Tue 30 Nov 2021 06:27

Hi!
this topic is highly interesting for me too, ‘cause I have the same problems.
I use the following products
- DB2 version 9.7
- RAD Studio XE7 + update 1
1. I created a test sample, trying to open the non-existent table
“select count(*) from QQTable”
2. I created the following code for the OnError event for the connection
void __fastcall TDMDB2::DB2ConnRError(TObject *Sender, EDAError *E, bool &Fail)
{
DMDB2->ErrMsg = E->Message;
DMDB2->ErrCode = E->ErrorCode;
DMDB2->ErrIsFatalError = E->IsFatalError();
DMDB2->ErrIsKeyViolation = E->IsKeyViolation();
Form1->Memo1->Lines->Add("*** EDAError ***");
Form1->Memo1->Lines->Add("ErrMsg = " + DMDB2->ErrMsg);
Form1->Memo1->Lines->Add("ErrCode = " + IntToStr(DMDB2->ErrCode));
EODBCError *EMyODBC;
EMyODBC = (EODBCError *)E;
DMDB2->NativeErrCode = EMyODBC->NativeErrorCode;
DMDB2->ErrMsg = EMyODBC->Message;
DMDB2->ErrCode = EMyODBC->ErrorCode;
/*---------------------------------------*/
Form1->Memo1->Lines->Add(" ");
Form1->Memo1->Lines->Add("*** EMyODBC ***");
Form1->Memo1->Lines->Add("ErrMsg = " + DMDB2->ErrMsg);
Form1->Memo1->Lines->Add("ErrCode = " + IntToStr(DMDB2->ErrCode));
Form1->Memo1->Lines->Add("NativeErrCode = " + IntToStr(DMDB2->NativeErrCode));
/*---------------------------------------*/
EUniError *EMy;
EMy = (EUniError *)E;
DMDB2->ErrMsg = EMy->Message;
DMDB2->ErrCode = EMy->ErrorCode;
Form1->Memo1->Lines->Add(" ");
Form1->Memo1->Lines->Add("*** EUniError ***");
Form1->Memo1->Lines->Add("ErrMsg = " + DMDB2->ErrMsg);
Form1->Memo1->Lines->Add("ErrCode = " + IntToStr(DMDB2->ErrCode));
}

And when I run the sample I got the following result
ODBC connection – OK
*** EDAError ***
ErrMsg = [IBM][CLI Driver][DB2/NT64] SQL0204N "MPTECH.QQTABLE" is an undefined name. SQLSTATE=42704
ErrCode = -1
*** EMyODBC ***
ErrMsg = [IBM][CLI Driver][DB2/NT64] SQL0204N "MPTECH.QQTABLE" is an undefined name. SQLSTATE=42704
ErrCode = -1
NativeErrCode = 0
*** EUniError ***
ErrMsg = [IBM][CLI Driver][DB2/NT64] SQL0204N "MPTECH.QQTABLE" is an undefined name. SQLSTATE=42704
ErrCode = -1
ODBC connection - Query Error
Operation aborted
Both ErrorCode and NativeErrCode are empty (0)
Tested with UniDAC 7.2.6 and 8.4.2

WaveRunner
Posts: 4
Joined: Wed 17 Nov 2021 17:04

Re: IBM DB2 incorrect ErrorCode

Post by WaveRunner » Mon 06 Dec 2021 08:18

Solved.

If somebody will faced w/ that problem try the following solution:

Code: Select all

EUniError* uniErr = dynamic_cast<EUniError*>(E);
if(!uniErr) return;

EODBCError* odbcErr = dynamic_cast<EODBCError*>(uniErr->InnerError);
if(!odbcErr) return;

lastDbErrorCode = odbcErr->NativeErrorCode;

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: IBM DB2 incorrect ErrorCode

Post by MaximG » Mon 06 Dec 2021 08:46

We are glad that you found a necessary solution. Please don't hesitate to contact us with questions concerning UniDAC usage.

Post Reply