Preventing access error messages, (C++)

  • Thread starter Thread starter Simon
  • Start date Start date
S

Simon

Hi,

In my C++ code I try and run a query to delete data older than a certain
date.
The query is fairly straight forward.

....
strSQL = "DELETE FROM Log WHERE DateTime < ";
strSQL += dtDelete.Format("#%m/%d/%y %H:%M:%S#");"
....
Where the value dtDelete is a 365 days ago.

I then check that the database is open and that the query does not already
exists.

bool bExists = true;
CDaoQueryDef qdCheck(m_pDaoDatabase);
try
{
qdCheck.Open("logdelete");
}
catch( CDaoException* e )
{
// query does not exist so clear the flag
bExists = false;
e->Delete();
}

....
if it exists remove it, (also surrounded by try/catch(CDaoException* e)
....

try{
CDaoQueryDef query(m_pDaoDatabase);
query.Create("", strQuery);
query.Execute();
query.Close();
}
catch (CDaoException* e)
{
CString strError;
strError = "Could not execute query: ";
strError += e->m_pErrorInfo->m_strDescription;
e->Delete();
return false;
}
return true;

....

But sometimes I get the message "The Microsoft Jet Database Engine could not
find the object "logdelete"..."

Why would that be? How can I prevent the messages from appearing?

Could it be that I need to add a more general try/catch in some cases?
Any ideas?

Simon
 
Presumably logdelete is a saved query, and you're changing its SQL to what's
in strSQL. You haven't shown that part of your code...
 
Presumably logdelete is a saved query, and you're changing its SQL to
what's
in strSQL. You haven't shown that part of your code...

I am not sure i follow.

Yes "logdelete" might be a saved query that we want to delete, if it does
exists then we delete it.

And i did give the querry for strSQL, the value of the date is today's
date -365 days.

Was it what you were asking?

Simon
 
Sorry, I guess I got distracted!

The error message you're getting specifically relates to logdelete not being
there. Why are you trying to delete it? I don't see anything else in your
code that refers to logdelete other than your attempt to delete it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top