
var fd = new OpenfileDialog();if (fd.ShowDialog() == DialogResult.OK){ var extendedPropertIEs = string.Empty; if (fd.filename.Contains(".xlsx")) { // excel 2007 xml format file,IMEX = import data as text avoIDs data conversion errors extendedPropertIEs = "Excel 12.0 Xml;IMEX=1"; } else if (fd.filename.Contains(".xls")) { // excel 2003 format file,IMEX: import data as text avoIDs data conversion errors extendedPropertIEs = "Excel 8.0;IMEX=1"; } var connectionString = "ProvIDer=Microsoft.ACE.olEDB.12.0;Data Source='" + fd.filename + "';Extended PropertIEs='" + extendedPropertIEs + "'"; using (var objXConn = new oleDbConnection(connectionString)) { objXConn.open(); var selectStatement = string.Format("SELECT * FROM [tabname$] WHERE FormType IS NOT NulL"); var datatable = new Datatable("test"); using (var objCommand = new oleDbCommand(selectStatement,objXConn)) { var dataReader = objCommand.ExecuteReader(); if (dataReader != null) { datatable.Load(dataReader); } } using (var stringWriter = new StringWriter()) { datatable.WriteXml(stringWriter); this.textBox1.Text = stringWriter.ToString(); } }} 使用oleDbDataAdapter而不是oleDbCommand.ExecuteReader()可以重现该行为.
using (var dataAdapter = new oleDbDataAdapter(selectStatement,objXConn)){ dataAdapter.Fill(datatable);} 失败,我的意思是在datatable.Load(dataReader)行上发生以下错误;
使用x86配置运行/构建程序时,出现以下错误.
System.Data.oleDb.oleDbException (0x80004005): UnkNown at System.Data.oleDb.oleDbDataReader.ProcessResults(oleDbHResult hr) at System.Data.oleDb.oleDbDataReader.GetRowHandles() at System.Data.oleDb.oleDbDataReader.ReadRowset() at System.Data.oleDb.oleDbDataReader.Read() at System.Data.Common.DataAdapter.FillLoadDaTarow(SchemaMapPing mapPing) at System.Data.Common.DataAdapter.FillFromreader(DataSet dataset,Datatable datatable,String srctable,DataReaderContainer dataReader,Int32 startRecord,Int32 maxRecords,DataColumn parentChapterColumn,Object parentChapterValue) at System.Data.Common.DataAdapter.Fill(Datatable[] datatables,IDataReader dataReader,Int32 maxRecords) at System.Data.Common.LoadAdapter.FillFromreader(Datatable[] datatables,Int32 maxRecords) at System.Data.Datatable.Load(IDataReader reader,LoadOption loadOption,FillErrorEventHandler errorHandler) at ExcelTest.Form1.button1_Click(Object sender,EventArgs e) at System.windows.Forms.Control.OnClick(EventArgs e) at System.windows.Forms.button.OnClick(EventArgs e) at System.windows.Forms.button.onmouseup(MouseEventArgs mevent) at System.windows.Forms.Control.WmMouseUp(Message& m,Mousebuttons button,Int32 clicks) at System.windows.Forms.Control.WndProc(Message& m) at System.windows.Forms.buttonBase.WndProc(Message& m) at System.windows.Forms.button.WndProc(Message& m) at System.windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)
使用Anycpu / x64配置运行/构建程序时,我在两台计算机上都出现以下错误.
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,DbConnectionPoolKey poolKey,Object poolGroupProvIDerInfo,DbConnectionPool pool,DbConnection owningObject) at System.Data.ProvIDerBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection,DbConnectionPoolGroup poolGroup,DbConnectionoptions userOptions) at System.Data.ProvIDerBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,taskcompletionsource`1 retry,DbConnectionoptions userOptions,DbConnectionInternal oldConnection,DbConnectionInternal& connection) at System.Data.ProvIDerBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,DbConnectionFactory connectionFactory,DbConnectionoptions userOptions) at System.Data.ProvIDerBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory) at System.Data.oleDb.oleDbConnection.open() at ExcelTest.Form1.button1_Click(Object sender,EventArgs e) at System.windows.Forms.button.onmouseup(MouseEventArgs mevent) at System.windows.Forms.Control.WmMouseUp(Message& m,Int32 clicks) at System.windows.Forms.Control.WndProc(Message& m) at System.windows.Forms.buttonBase.WndProc(Message& m) at System.windows.Forms.button.WndProc(Message& m) at System.windows.Forms.NativeWindow.Callback(IntPtr hWnd,IntPtr lparam)
用于测试的Excel文件在两台计算机上都是相同的文件.我已经能够使用多个文件(.xls ans .xlsx)重现该问题.
我已经尝试了以下方法来解决这个问题.
>安装‘Microsoft.ACE.OLEDB.12.0’ provider is not registered on the local machine中描述的组件
>将项目配置为x86 / x64
>卸载并重新安装2007 Office System Driver: Data Connectivity Components
>卸载并重新安装Microsoft Access Database Engine 2010 Redistributable
我可以采取哪些额外步骤来解决问题或解决此问题?
解决方法 对于第一个问题,请使用oleDbDataAdapter和Fill()方法或Update().Datatable newTbl = new Datatable() using(oleDbDataAdapter ad = new oleDbDataAdapter( @"SELECT * FROM [tabname$] WHERE FormType IS NOT NulL",objXConn)) { oleDbCommandBuilder builder = new oleDbCommandBuilder(ad); builder.QuotePrefix = "["; builder.QuoteSuffix = "]"; // Saves the data set ad.Update(newTbl); } 用于32位和64位应用的olEDB驱动程序是不同的.
如果您只安装了32位驱动程序,则64位应用程序尝试使用它将收到此错误:Microsoft.ACE.olEDB.12.0’提供程序未在本地计算机上注册.同样,如果您只安装了64位版本并且32位应用程序尝试使用它,则会出现此错误.
要了解发生了什么,您应该检查您的应用程序是什么.我认为这一行可以提供帮助:Environment.Is64BitProcess
如果xls(Excel 2003)文件出现问题,请尝试使用JET连接字符串!
编辑:
以下是drivers的链接:
以上是内存溢出为你收集整理的c# – OleDbException(0x80004005):未知全部内容,希望文章能够帮你解决c# – OleDbException(0x80004005):未知所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)