Hello All!
I am using access object to run a module in my access database. The module runs fine. However, the database does not get closed even though I have tried many things to quit\close\release objects. Everytime the calling class tries to open a connection to that db, I get an error saying "cannot use the file".
Following is my code -
-----------------------------------------------------------------------------------------
Access.Application accessObj = null;
accessObj = new Application();
try
{
accessObj.OpenCurrentDatabase(dbPath, true, null);
accessObj.DoCmd.TransferText(AcTextTransferType.ac ImportDelim, importSpecificationName, tableName, filePath, false, null, null);
DAO.TableDefs tdfs = accessObj.CurrentDb().TableDefs;
foreach (DAO.TableDef td in tdfs)
{
if (td.Name.Contains("_ImportErrors"))
{//log error }
}
if (isSuccess)
{
object oMissing = System.Reflection.Missing.Value;
object result = accessObj.Run(functionName, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing);
accessObj.DoCmd.Close(AcObjectType.acModule, moduleName, AcCloseSave.acSaveNo);
}
accessObj.CloseCurrentDatabase();
accessObj.DoCmd.Close(AcObjectType.acDefault, null, AcCloseSave.acSaveNo);
}
catch (Exception exp)
{
}
finally
{
accessObj.Quit(AcQuitOption.acQuitSaveNone);
Marshal.ReleaseComObject(accessObj);
Marshal.FinalReleaseComObject(accessObj);
accessObj = null;
}
-----------------------------------------------------------------------------------------
I have been trying to fix this for long now. Please someone help me see what wrong I am doing here.
Thank you in advance...