1

Topic: CDatabase exception

I write the following code (approximately):

try
{
Database MyDB;
MyBD.OpenEx (_T ("DSN=my_odbc; UID=user; PWD=1234;"), CDatabase:: noOdbcDialog);
MyDB.ExecuteSQL ("{CALL sp_Any_Procedure ()}");
MyDB.Close ();
}
catch (...)
{
}

I launch - all remarkably.
But we assume that  with a name sp_Any_Procedure does not exist, then CDatabase "swears" in a type     (that is not necessary to me at all), i.e. never there are exceptions which I can process (namely to do nothing).
Prompt how to overcome this    ?

 [color=green] kxm [/color] [color=yellow] e [/color] [color=green] p [/color] 

2

Re: CDatabase exception

You say lies all. Wrote, precisely such code, all works.
(Driver MSAccess)

3

Re: CDatabase exception

Unfortunately, I do not say lies sad
At me:
1. The server: MS a SQL Server
2. Source ODBC: System DSN (my_odbc)
Probably with MSAccess works. Though I doubt, since in ExecuteSQL is caused AFX_ODBC_CALL with subsequent AfxThrowDBException which in the  is processed in wincore.cpp:

...
CATCH_ALL (e)
{
lResult = AfxProcessWndProcException (e, &pThreadState->m_lastSentMsg);
TRACE (traceAppMsg, 0, "Warning: Uncaught exception in WindowProc (returning %ld).\n";
lResult);
DELETE_EXCEPTION (e);
}

And so, function AfxProcessWndProcException displays  which is not necessary to me. And generally never the error "reaches" my output agent.

 [color=green] kxm [/color] [color=yellow] e [/color] [color=green] p [/color] 

4

Re: CDatabase exception

kxmep wrote:

I Write the following code (approximately):

try
{
Database MyDB;
MyBD.OpenEx (_T ("DSN=my_odbc; UID=user; PWD=1234;"), CDatabase:: noOdbcDialog);
MyDB.ExecuteSQL ("{CALL sp_Any_Procedure ()}");
MyDB.Close ();
}
catch (...)
{
}

I launch - all remarkably.
But we assume that  with a name sp_Any_Procedure does not exist, then CDatabase "swears" in a type     (that is not necessary to me at all), i.e. never there are exceptions which I can process (namely to do nothing).
Prompt how to overcome this    ?

 [color=green] kxm [/color] [color=yellow] e [/color] [color=green] p [/color] 

Well and make the handler was specific for this type of exceptions. That is before catch (...) interpose catch (CDBException &e) {} and check up under a debugger...
All should be caught...

5

Re: CDatabase exception

At first,

 catch (CDBexception (*,& e) 

should not to help, since catch (...) Includes also it exception.
Secondly, I made I am empty an aaplet with the specified text and was connected to MSSQL. And changed nothing, i.e. all fulfilled.
And at what here wincore.cpp if exception it should be caught directly in a body of your function?

6

Re: CDatabase exception

Vej wrote:

And at what here wincore.cpp if exception it should be caught directly in a body of your function?

Looked :
At performance ExecuteSQL (dbcore.cpp) we get on code location:
...
AFX_ODBC_CALL (:: SQLExecDirect (hstmt, reinterpret_cast <SQLTCHAR *> (pszSQL), SQL_NTS));
if (! CheckHstmt (nRetCode, hstmt)) AfxThrowDBException (nRetCode, this, hstmt);
...
Since such  on the server is not present - it is fulfilled AfxThrowDBException and it is processed there and then:
...
CATCH_ALL (e)
{
:: SQLCancel (hstmt);
AFX_SQL_SYNC (:: SQLFreeStmt (hstmt, SQL_DROP));
THROW_LAST ();
}
END_CATCH_ALL
...
In turn THROW_LAST  in wincore.cpp:
...
CATCH_ALL (e)
{
lResult = AfxProcessWndProcException (e, &pThreadState->m_lastSentMsg);
TRACE (traceAppMsg, 0, "Warning: Uncaught exception in WindowProc (returning %ld).\n";
lResult);
DELETE_EXCEPTION (e);
}
AfxProcessWndProcException - shows
DELETE_EXCEPTION - There is no error, i.e. to me it does not come (yes already and it is not necessary since  is already shown sad)
Can at the adjustment project what-thread not those?
MFC, ATL...

 [color=green] kxm [/color] [color=yellow] e [/color] [color=green] p [/color] 

7

Re: CDatabase exception

Well give the method of successive approximations smile
I apply the tiny project in which all works (only a source name change for the).
You too try to isolate a small slice of the project that did not work (I I can download and big, but it probably confidential).
That that THROW_LAST () is processed in WndProc, it is abnormal.
There can be at you any unhealthy multithreading? Or the timer?

8

Re: CDatabase exception

1. Thanks for the tiny project
2. Forgive me - the asshole smile
All is correctly processed (really errors are caught). I not the correct code threw it... Thought that there is no difference with:

CDatabase* MyDB;
MyDB = new CDatabase;
try
{
MyDB-> OpenEx (_T ("DSN=isa_odbc; UID=isa_writer; PWD=12345678;"), CDatabase:: noOdbcDialog);
MyDB-> ExecuteSQL ("{CALL sp_Any ()}");
MyDB-> Close ();
delete MyDB;
}
catch (...)
{
if (MyDB)
{
delete MyDB;
}
}

I use this variant because it seems to me that in the first variant MyDB will not be deleted from storage, and here I do delete MyDB.
I am not right?

 [color=green] kxm [/color] [color=yellow] e [/color] [color=green] p [/color] 

9

Re: CDatabase exception

No, it is not right.
In that case that you wrote at first (and as is made in my project) MyDB (as well as almost any local variable) "dies" on an output from this the unit in which has been declared (the unit it roughly telling that that is restricted {}). And storage will be released.
And in a case with new one suffices delete after the unit try/catch.
Likely, in a case with new the size of an EXE file decreases.
So all the same, works or not? In what there was a business?

10

Re: CDatabase exception

> Likely, in a case with new the size of an EXE file decreases.
File size same.
> So all the same, works or not? In what there was a business?
If to use

 MyDB = new CDatabase 

catching of errors does not work sad
Rewrote on

 CDatabase MyDB 

- works, as you and wrote: "Wrote, precisely such code, all works."
Big , I will test.
:
> But it probably the confidential
It is the filter for ISA Server

 [color=green] kxm [/color] [color=yellow] e [/color] [color=green] p [/color] 

11

Re: CDatabase exception

The size of an ehe-file changes in quanta, is normal on 4, therefore it is necessary to declare many variables that it became noticeable :-) Likely, it is visible on arrays (changeover static on dynamic) is better.
Works and with

 MyDB = new CDatabase 

. No difference for catching of exceptions here is present (try to make it in my project).
Please, is glad to help.