I am trying to get values from a DB in my local system to Excel Sheet. This is my code
private void button1_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.Application Text_To_Excel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbooks Excel_File = (Microsoft.Office.Interop.Excel.Workbooks)Text_To_Excel.Workbooks;
Excel_File.OpenDatabase(@"C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\SportsStore.mdf");
Text_To_Excel.ActiveWorkbook.SaveAs(location + "Mq.xlsx", Microsoft.Office.Interop.Excel.XlFileFormat.xlOpenXMLWorkbook, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
Text_To_Excel.ActiveWorkbook.Close(false, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
}
When I run it, I get a COMException was unhandled error
Exception from HRESULT: 0x800A03EC
with error code
-2146827284
What am I doing wrong here and how do I resolve it ?