private bool ExportToExtrato() { // https://www.aspsnippets.com/Articles/The-OLE-DB-provider-Microsoft.Ace.OLEDB.12.0-for-linked-server-null.aspx var retorno = true; using (var ctx = new MoneyBinEntities()) { ctx.spExportToAccessExtrato(_saveAs); } MoneyBinDB.ExportToExtrato(_saveAs); var tempFile = Path.Combine(Path.GetDirectoryName(_saveAs), Path.GetRandomFileName() + Path.GetExtension(_saveAs)); var app = new Microsoft.Office.Interop.Access.Application { Visible = false }; try { app.CompactRepair(_saveAs, tempFile, false); var temp = new FileInfo(tempFile); temp.CopyTo(_saveAs, true); temp.Delete(); } catch (Exception e) { MessageBox.Show(e.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); retorno = false; //throw; } finally { app.Quit(); } return(retorno); }