Microsoft.ACE.OLEDB.12.0
将代码部署到测试机器上,因为使用了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)
其中,连接代码如下:
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即可。
posted on 2011-01-04 16:21 blackcore 阅读(23120) 评论(3) 编辑 收藏 举报