This question is a continuation of this issue.
I have some C# code that uses late binding for compacting a database:
public bool CompactAccessDatabase(string strSourceDB, string strTargetDB, string strPassword)
{
try
{
// Get the DBEngine property
dynamic dbEngine = Activator.CreateInstance(Type.GetTypeFromProgID("DAO.DBEngine.120"));
// Build the DB connection string
string strDecryptedPassword = "";
string strDBConnectionString = "";
if(!string.IsNullOrEmpty(strPassword))
{
if (!DecryptDatabasePassword(strPassword, ref strDecryptedPassword))
{
SimpleLog.Log("DecryptDatabasePassword returned false");
}
strDBConnectionString = ";pwd=" + strDecryptedPassword;
}
// Perform the compact
dbEngine.CompactDatabase(strSourceDB, strTargetDB, null, null, strDBConnectionString);
}
catch (Exception ex)
{
SimpleLog.Log(ex);
return false;
}
return true;
}
In itself it is functioning fine. My C++ calling wrapper:
bool CMSATools::CompactAccessDatabase(CString strSourceDB, CString strTargetDB, CString strPassword)
{
VARIANT_BOOL vbResult = VARIANT_FALSE;
if (m_pInterface != nullptr)
{
CComBSTR bstrSourceDB(strSourceDB.AllocSysString());
CComBSTR bstrTargetDB(strTargetDB.AllocSysString());
CComBSTR bstrPassword(strPassword.AllocSysString());
throw_if_fail(m_pInterface->CompactAccessDatabase(bstrSourceDB, bstrTargetDB, bstrPassword, &vbResult));
}
return vbResult == VARIANT_TRUE ? true : false;
}
What I am finding is that when I run my C++ app (x64) in release or debug and I execute this code, whilst it compacts, when I shut the app down I get this exception:
Am I missing a step here?