On production system we are SOMETIMES getting below error message while reading excel into datatable (same code same file will not work today but will on other day) .
System.Data.OleDb.OleDbException (0x80004005): Invalid argument. System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) at
System.Data.OleDb.OleDbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
But the problem is that on production server it work well today but tomorrow or day after tomorrow it will not work well and then again it will start working well.
Below is the code.
string ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + readFilePath + ";Extended Properties=\"Excel 12.0;\"";
ExcelConnection = new OleDbConnection(ConnectionString);
string ExcelQuery = "Select FORMAT(SAMPDATE,'dd/MM/yyyy') as SAMPDATE,FORMAT(LANDED_ON,'dd/MM/yyyy') as LANDED_ON,FORMAT(RECDATE,'dd/MM/yyyy') as RECDATE,* from [Sheet1$]";
ExcelCommand = new OleDbCommand(ExcelQuery, ExcelConnection);
ExcelConnection.Open();
ExcelAdapter = new OleDbDataAdapter(ExcelCommand);
ExcelAdapter.Fill(dtbExcelData);
ExcelConnection.Close();
I have also checked value of variable readFilePath it is correct , example value is D:\Cop\Web\ABC\PAL\FIleUploaded\ER01.xls.
I am not sure why exactly same code does not allow same excel document to get uploaded but next day same code same file works without any problem. Can somebody help me?