我正在尝试在excel文件上使用ACE OleDB 16。并获得{"尝试读取或写入受保护的内存。这通常表明其他内存已损坏。"}
系统是Office 2016和程序文件(x86)\ Common \ Microsoft Shared \ Office 16 \ ACEOLEDB.dll
对于正在发生的事情的任何输入都将非常感激(甚至被称为白痴:))
注意:虽然代码在try-catch块中,但程序会抛出错误;
示例代码:
string path = @"testfile.xlsx";
string connString = "Provider=Microsoft.ACE.OLEDB.16.0;Data Source="+ path +";Extended Properties='Excel 16.0;HDR=No;IMEX=1;'";
DataTable dt = new DataTable();
try
{
OleDbConnection cnnxls = new OleDbConnection(connString);
OleDbDataAdapter oda = new OleDbDataAdapter(string.Format("select * from [{0}$]", sheet), cnnxls);
oda.Fill(dt);
}
catch (Exception e)
{
// error handling
}
错误输出:
System.AccessViolationException未处理HResult = -2147467261
Message =尝试读取或写入受保护的内存。这通常是一个 指示其他内存已损坏。来源= System.Data
堆栈跟踪: 在System.Data.OleDb.DataSourceWrapper.InitializeAndCreateSession(OleDbConnectionString) constr,SessionWrapper& sessionWrapper) 在System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr,OleDbConnection连接) 在System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions) options,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo, DbConnectionPool池,DbConnection owningObject) 在System.Data.ProviderBase.DbConnectionFactory.CreateConnection(DbConnectionOptions) options,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo, DbConnectionPool池,DbConnection owningConnection, DbConnectionOptions userOptions) 在System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection) owningConnection,DbConnectionPoolGroup poolGroup,DbConnectionOptions USEROPTIONS) 在System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1次重试,DbConnectionOptions userOptions) 在System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory, TaskCompletionSource`1重试,DbConnectionOptions userOptions) 在System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory) 在System.Data.OleDb.OleDbConnection.Open() 在System.Data.Common.DbDataAdapter.FillInternal(DataSet数据集,DataTable [] datatables,Int32 startRecord,Int32 maxRecords, String srcTable,IDbCommand命令,CommandBehavior行为) 在System.Data.Common.DbDataAdapter.Fill(DataTable [] dataTables,Int32 startRecord,Int32 maxRecords,IDbCommand命令, CommandBehavior行为) 在System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) 在C:\ Users \ anokano \ documents \ visual中的AceOleDbTest.AceOleDbTest.AceReadTest(String connString,String logPath,String sheet) studio 2015 \ Projects \ AceOleDbTest \ AceOleDbTest \ AceOleDbTest.cs:第87行 at randomtests3.Program.Main(String [] args)在C:\ Users \ anokano \ Documents \ Visual Studio中 2015 \ Projects \ randomtests3 \ randomtests3 \ Program.cs:第336行 在System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String [] args) 在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在System.Threading.ThreadHelper.ThreadStart_Context(对象状态) 在System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback回调,对象状态,布尔值 preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx) 在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态) 在System.Threading.ThreadHelper.ThreadStart()InnerException: