1. 程式人生 > >找不到Microsoft Access Driver(*.mdb)ODBC驅動程式的安裝例程。請重新安裝驅動

找不到Microsoft Access Driver(*.mdb)ODBC驅動程式的安裝例程。請重新安裝驅動

將程式碼部署到測試機器上,因為使用了OLEDB操作Excel,程式出現如下錯誤:

複製程式碼 System.InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. 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 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(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
複製程式碼

其中,連線程式碼如下:

?
1 Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Excel 12.0 Xml;HDR=YES;

出現以上錯誤後,先安裝一個元件,如果不行再設定IIS即可。

因為伺服器上未安裝Microsoft office,所以從官網上下載了一個包:AccessDatabaseEngine.exe

相關說明:

This download will install a set of components that facilitate the transfer of data between existing Microsoft Office files such as Microsoft Office Access 2007 (*.mdb and *.accdb) files and Microsoft Office Excel 2007 (*.xls, *.xlsx, and *.xlsb) files to other data sources such as Microsoft SQL Server. Connectivity to existing text files is also supported.

安裝完成後,還需要在IIS連線池配置一個屬性即可:

開啟IIS-->找到與網站相對應的應用程式池-->高階設定-->常規-->啟用32位應用程式的值為:True即可。