I am facing a strange problem with an tool, that should be able to read data from an Excel file and write it into a SQL-Database.
string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=" + filename + ";" +
"Extended Properties=\"Excel 12.0 Xml;HDR=YES\"";
DataTable dt;
OleDbDataAdapter dataAdapter;
dataAdapter = new OleDbDataAdapter("SELECT * FROM [" + sheet + "$]", strConn);
dt = new DataTable();
try
{
dataAdapter.Fill(dt); //Programm reagiert nicht mehr
}
catch(Exception ex)
{
Logger("Problem filling Adapter: " + ex.ToString());
return null;
}
The following exception occurs at dataAdapter.Fill(dt)
Problem filling Adapter: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at System.Data.OleDb.DataSourceWrapper.InitializeAndCreateSession(OleDbConnectionString constr, SessionWrapper& sessionWrapper) at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.OleDb.OleDbConnection.Open() 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) at ExcelExportWindowsForms.Program.ReadExcel(String filename, String sheet)
The interesting thing is, that this works perfectly on my machine (Excel 2013), but does not on a server with Excel 2003. Could this be the reason?
Extended Properties="Excel 8.0;
– HoneyBadger