1

我有一个 VB.NET WinForm 应用程序,其中打开了与 MS Access 2002 数据库的 OLEDB 连接,如下所示:

Private Function MakeNewConnection(FullPath) As OleDbConnection
    Dim Conn As OleDbConnection = New OleDbConnection()
    Try
        Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + FullPath
        Conn.Open()
    Catch ex As Exception
        Throw ex
    End Try

    Return Conn
End Function

虽然这通常可以正常工作,但它偶尔会在 Windows XP 32 位计算机 (SP3) 上生成错误。这是零星的,因为有时它工作得很好,有时它只是抛出一个错误!有两种类型的消息:未指定的错误或“Microsoft.Jet.OLEDB.4.0”提供程序未在本地计算机上注册。您将在本文末尾找到异常的堆栈跟踪。

我已经做了很多搜索。“提供者”错误主要与 64 位窗口有关。就我而言,它是一个 32 位系统!

任何想法?

详细错误:

Error message: Unspecified error
Stack trace:    
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 QueryAgent.MakeNewConnection()    

Error message: the 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine
Stack trace:    at  System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr,  DataSourceWrapper& datasrcWrapper)
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 QueryAgent.MakeNewConnection()
4

1 回答 1

0

只需将构建选项的构建从任何 CPU 选项更改为您的系统(32 位)。转到构建>>>配置>>>然后将构建选项从 AnyCPU 更改为您的系统特定!您还可以从 Microsoft 下载第 12 版的 OLE-DB。如果您在 VS 中使用更高版本的 MS Access,这将有所帮助,因为这就是我最初可以克服错误的方式(使用多个操作系统和软件)。注意:当移动到更高版本的软件时,请保留一个旧副本(备份),因为如果一个是由新版本定制的,它可能无法在旧版本中使用。

于 2012-10-10T16:37:24.827 回答