Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AccessViolationException when filling DataTable

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?

like image 891
xileb0 Avatar asked Jan 24 '26 09:01

xileb0


1 Answers

(from comment)

In your comments you mention you installed the latest AccessDatabaseEngine. I've had problems with that as well (at the time I found lots of references of people with the same problem, but don't have those links anymore). I had to use the 2010 version. Might be something to try if all else fails (you probably have to uninstall the other version first). The reason is unclear (to me anyway), but it may have something to do with x86 v x64 installations.

like image 131
HoneyBadger Avatar answered Jan 25 '26 21:01

HoneyBadger



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!