SEHException:外部组件引发了异常。

3

我正在使用VS 2010和MS Access 2010。Microsoft Access Database engine 2010也已安装。操作系统版本为64位的Windows 7 Enterprise。

以下是我的代码,我在这里遇到了异常。同时,我也粘贴了堆栈跟踪。

DCXManagerTableAdapters.AppDefaultOptionTableAdapter dataAdapter = new DCXManagerTableAdapters.AppDefaultOptionTableAdapter();

dataAdapter.Connection.ConnectionString = DB.ConnectionString;

if (dataAdapter.Connection.State == ConnectionState.Closed)

{dataAdapter.Connection.Open();} \* Here i am getting exception

内部异常:System.Runtime.InteropServices.SEHException(0x80004005):外部组件抛出了一个异常。在System.Data.OleDb.DataSourceWrapper.InitializeAndCreateSession(OleDbConnectionString constr,SessionWrapper& sessionWrapper)中,在System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr,OleDbConnection connection)中,在System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo,DbConnectionPool pool,DbConnection owningObject)中,在System.Data.ProviderBase.DbConnectionFactory.CreateConnection(DbConnectionOptions options,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo,DbConnectionPool pool,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)中,在System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource1 retry,DbConnectionOptions userOptions)中,在System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory,TaskCompletionSource`1 retry,DbConnectionOptions userOptions)中,在System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory)中,在System.Data.OleDb.OleDbConnection.Open()中,在D:\BRANSON-SVN\Solution\Branson.DataAccess\Providers\GraphTabProvider.cs的Branson.DataAccess.Providers.GraphTabProvider.GetAppDefaultOption()中:line 180,在D:\BRANSON-SVN\Solution\Branson.Controller\GraphTabController.cs的Branson.Controller.GraphTabController.GetAppDefaultOption()中:line 37,在D:\BRANSON-SVN\Solution\Branson.DCXManager\Branson.DCXManager\App.xaml.cs的Branson.DCXManager.App.OnStartup(StartupEventArgs e)中:line 174,在System.Windows.Application.<.ctor>b__1(Object unused)中,在System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback,Object args,Int32 numArgs)中,在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source,Delegate method,Object args,Int32 numArgs,Delegate catchHandler)中。

看起来错误与打开数据库连接有关。你的连接字符串是什么? - Bradley Uffner
你最终解决了这个问题吗? - Rob K.
1个回答

0
如果此连接曾经工作过但现在停止了,可能是由于对文件的打开句柄引起的。
您需要确保没有其他进程持有您的访问文件或 Excel 文件的句柄。
您可以使用 Process Explorer 轻松完成此操作,这是 Sysinternals 套件中的一个调试应用程序。
您可以从此处下载 Process Explorer 作为独立应用程序: https://technet.microsoft.com/en-us/sysinternals/bb896653
  1. 打开“进程监视器”
  2. 在主工具栏中选择“查找”选项卡
  3. 选择“查找句柄或 DLL…”
  4. 输入您要查询的文件,如“MyExcel.xls”,则会显示所有指向您文件的句柄列表。
  5. 接下来,关闭持有文件的任何应用程序,然后再次运行您的应用程序。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接