954,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

CDBException can't solve problem

Hi all,

I'm facing this problem in my running app. It is a real-time app and writes to the database whenever data is received. However, there is rare occasions that causes the ExecuteSQL to fail. However, the failure did not throw any exception, so my CDBException did not detect anything(it is written in a try/catch).
I suspect that the data fail to insert into the database due to the database is being used heavily. Is CDBException able to catch this kind of error? Is there any way that I can solve this problem?
Or is it other problem(what are the error that CDBException can't handle)?

Thank you...

chiwawa10
Junior Poster
156 posts since Jul 2005
Reputation Points: 88
Solved Threads: 27
 

Not entirely sure, but you could try replacing the CDBException with AfxThrowDBException, which is the Global Error Exception (includes CDBException) and it may give you a more definitive message.

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
 

Dear paladine,

part of my code is like this:

TRY{
ExecuteSQL(...) //query to insert data into database
}

CATCH(CDBException e){
.....
}


*the situation that i face is the CDBException does not capture anything even though the data is not successfully inserted(especially when the database is busy). Do you know what is wrong???

Please advise...

chiwawa10
Junior Poster
156 posts since Jul 2005
Reputation Points: 88
Solved Threads: 27
 

OK, maybe I missed something. How do you know that ExecuteSQL has failed? By checking the DB? Is there any error message generated?

If the DB is that busy, consider using Transactions so to at least provide debug ability and reduce the chance of data corruption.

I am really curious has to how you know it fails, and the code in and around that statement.

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
 

ohh.. I found out that error occurs by checking the DB. There are some data not inserted into the DB but the program did not throw any CDBException. If it had thrown any exception, the error would have been logged to a file which I explicitly wrote(writing the m_strError to the log file).

Locking the database is not an option because the database must be accessible by another program which is continuously reading data from it.
This is a time critical/real-time program.

Is there any problem that you know of, that the CDBException cannot handle?
thank you...

chiwawa10
Junior Poster
156 posts since Jul 2005
Reputation Points: 88
Solved Threads: 27
 

Not that I know of. by why not do this as a transaction, that way it would be an all or none, and it may provide you a better idea of when/why it is failing?

Paladine
Master Poster
Team Colleague
824 posts since Feb 2003
Reputation Points: 211
Solved Threads: 27
 

ok... how can I implement transaction in my code?
I know there is a function called BeginTrans() but since I'm using ExecuteSQL(), is it relevant?
any example would be nice, thank you!

chiwawa10
Junior Poster
156 posts since Jul 2005
Reputation Points: 88
Solved Threads: 27
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You