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\rele ase 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.Applicat ion accessObj = null;
accessObj = new Application();
try
{
accessObj.OpenC urrentDatabase( dbPath, true, null);
accessObj.DoCmd .TransferText(A cTextTransferTy pe.acImportDeli m, importSpecifica tionName, tableName, filePath, false, null, null);
DAO.TableDefs tdfs = accessObj.Curre ntDb().TableDef s;
foreach (DAO.TableDef td in tdfs)
{
if (td.Name.Contai ns("_ImportErro rs"))
{//log error }
}
if (isSuccess)
{
object oMissing = System.Reflecti on.Missing.Valu e;
object result = accessObj.Run(f unctionName, 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(AcObject Type.acModule, moduleName, AcCloseSave.acS aveNo);
}
accessObj.Close CurrentDatabase ();
accessObj.DoCmd .Close(AcObject Type.acDefault, null, AcCloseSave.acS aveNo);
}
catch (Exception exp)
{
}
finally
{
accessObj.Quit( AcQuitOption.ac QuitSaveNone);
Marshal.Release ComObject(acces sObj);
Marshal.FinalRe leaseComObject( 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...
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\rele ase 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.Applicat ion accessObj = null;
accessObj = new Application();
try
{
accessObj.OpenC urrentDatabase( dbPath, true, null);
accessObj.DoCmd .TransferText(A cTextTransferTy pe.acImportDeli m, importSpecifica tionName, tableName, filePath, false, null, null);
DAO.TableDefs tdfs = accessObj.Curre ntDb().TableDef s;
foreach (DAO.TableDef td in tdfs)
{
if (td.Name.Contai ns("_ImportErro rs"))
{//log error }
}
if (isSuccess)
{
object oMissing = System.Reflecti on.Missing.Valu e;
object result = accessObj.Run(f unctionName, 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(AcObject Type.acModule, moduleName, AcCloseSave.acS aveNo);
}
accessObj.Close CurrentDatabase ();
accessObj.DoCmd .Close(AcObject Type.acDefault, null, AcCloseSave.acS aveNo);
}
catch (Exception exp)
{
}
finally
{
accessObj.Quit( AcQuitOption.ac QuitSaveNone);
Marshal.Release ComObject(acces sObj);
Marshal.FinalRe leaseComObject( 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...