Error Handling with ADO
Posted
by Waleed Darwish
on June 19th, 1999
I'm new to ADO and I searched for a piece of code to handle errors, I found the following code snippet in an article and wanted to share it with other ADO developers that might be looking for something similar.
The following function (LogAdoErrorImport) can be called from any catch block in your program.
// Obtain information from the Errors Collection
HRESULT LogAdoErrorImport(_ConnectionPtr pConn)
{
ErrorsPtr pErrors;
ErrorPtr pError;
CString strTmp;
HRESULT hr = (HRESULT) 0L;
long nCount;
// Don't have an un-handled exception in the handler that
// handles exceptions!
try
{
pErrors = pConn->GetErrors();
nCount = pErrors->GetCount();
for( long i = 0; (!FAILED(hr)) && (i < nCount); i++ )
{
TRACE( "\t Dumping ADO Error %d of %d", i+1, nCount );
hr = pErrors->get_Item((_variant_t)((long)i), &pError );
_bstr_t bstrSource ( pError->GetSource() );
_bstr_t bstrDescription( pError->GetDescription() );
_bstr_t bstrHelpFile ( pError->GetHelpFile() );
_bstr_t bstrSQLState ( pError->GetSQLState() );
TRACE( "\n Number = %ld", pError->GetNumber() );
TRACE( "\n Source = %s", (LPCTSTR) bstrSource );
TRACE( "\n Description = %s", (LPCTSTR) bstrDescription );
TRACE( "\n HelpFile = %s", (LPCTSTR) bstrHelpFile );
TRACE( "\n HelpContext = %ld", pError->GetHelpContext() );
TRACE( "\n SQLState = %s", (LPCTSTR) bstrSQLState );
TRACE( "\n HelpContext = %ld", pError->GetHelpContext() );
TRACE( "\n NativeError = %ld", pError->GetNativeError() );
}
}
catch( CException *e )
{
TRACE( "*** UNABLE TO LOG EXCEPTION ***" );
e->Delete();
}
catch(...)
{
TRACE( "*** UNABLE TO LOG EXCEPTION ***" );
}
pErrors->Release();
pError->Release();
return hr;
}

Comments
Require information
Posted by Legacy on 05/08/2003 12:00amOriginally posted by: Ali Haider
I need some information, how to edit a ado recordset.
ReplyI am new one in programming feild.
Please help me.
error message when using large database
Posted by Legacy on 06/25/2002 12:00amOriginally posted by: Josh
Having a problem executing a query (under ADO recordset open method).
Using the error handling code, I get the description message:
"Not enough space on temporary disk"
My database is large: 390MB --> consisting mainly of one large table with 90 million+ records.
The query I execute should return about 15 million records.
After a few hours of processing my ADO code bombs out and get the above error logged.
The query works as expected on smaller databases.
I am confused because I have more than 10 GIG of memory on my hard drive. Is it possible this is all being filled?
Any insight would be appreciated!
ReplyMFC Programmer's Sourcebook
Posted by Legacy on 09/06/2001 12:00amOriginally posted by: G.Ravi Kiran
Replyhow to catch the error infomation
Posted by Legacy on 08/29/2001 12:00amOriginally posted by: emily
i use ado to connect a datasource using the following statement:
m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->Open("DSN=dd","","",-1);
but when the datasource "dd" is not exist,a fatal error will occur.would you kindly tell me how to avoid it?
ReplyHow to ExecuteSQL and commit transactions using ADO
Posted by Legacy on 06/01/2001 12:00amOriginally posted by: Sajjad Hussain
I'm using ADO control. I want to execute SQL statements through this control. I can navigate records, delete, update and add new records. Infact I have to delete a set of records from a table in .mdb under certain condition. For this I have to Execute SQL which I don't know how to execute. How to commit transactions through ADO.
Replynice/rough
Posted by Legacy on 04/08/2001 12:00amOriginally posted by: shahbaz khan
Good for some of the ruthless user like us.Thanx.
ReplyI am new in database interfaces using ADO and Visual C++
Posted by Legacy on 01/26/2001 12:00amOriginally posted by: Wael Eletlbany
hello everyone
ReplyCan anyone tell me about a website, book, or tutorial about how to connect a database to a Visual C++ interface using ADO. Given that the database is fully relational with multiple tables done using Access 2000. I am saying multiple table because I've seen an example for a single table databse.
Thank you
Wael
Unhandled Exception when using ADO
Posted by Legacy on 09/29/1999 12:00amOriginally posted by: Ovais Khan
Well i use ADO to convert my code from DAO. Most of the time it works fine but can anyone tell me which exception is raised by the ADO object. like DBException is raised by DAO in MFC. _com_error exception is not raised and i do not get the error description in some cases.
Ovais
ReplyUnknown error
Posted by Legacy on 08/11/1999 12:00amOriginally posted by: Simon Wang
In my program, I got a com error message said "Unknown error 0x800A0E78". Does anybody know what causes this? and what it means? Thanks!
ReplySome bugs
Posted by Legacy on 07/06/1999 12:00amOriginally posted by: Douglas Huang
ReplyLoading, Please Wait ...