Unable to read xlsx file through OleDb with the size more than ~1mb

删除回忆录丶 提交于 2019-12-24 00:15:45

问题


I'd like to use sql bulk copy in order to load data from *.xlsx file to the data base. But, I've faced the problem when file size is more than approximately 1mb. When I try to open OleDbConnection I get an error

No error message available, result code: E_FAIL(0x80004005)

Does anyone have an idea about such behavior?

P.S. If file size is less than mentioned above everything works as expected.

string connString = connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0 Xml;";

// Create the connection object 
OleDbConnection oledbConn = new OleDbConnection(connString);
// Open connection
oledbConn.Open();
// Create OleDbCommand object and select data from worksheet
OleDbCommand cmd = new OleDbCommand("SELECT * FROM [" + WorkSheetName + "$" + DataRange + "]", oledbConn);
OleDbDataReader dr = cmd.ExecuteReader();

string ProfDbBulkCopyConnString = ConfigurationManager.ConnectionStrings["DbBulkCopyConnString"].ToString();
SqlBulkCopy sb = new SqlBulkCopy(ProfDbBulkCopyConnString);
sb.ColumnMappings.Add("Status", "ActionStatus");
sb.ColumnMappings.Add("Process", "ProcessExec");
sb.DestinationTableName = "dba.Execute";
sb.WriteToServer(dr);

回答1:


Just a brief description of fixing. For more information I recommend to visit:

  • https://social.msdn.microsoft.com/Forums/en-US/4d1eeb6d-436d-4595-8645-fde90b2f9b18/oledb-error-opening-large-excel-2007-files-on-web-server?forum=adodotnetdataproviders
  • Export to excel spreadsheet (XLSX) failing
  • Microsoft ACE OLEDB connection creating empty Excel when there are 166,110 rows

Essentially, xlsx format is some kind of zip archive with a bunch of xml files. So, first of all ACEOLEDB provider try to unzip all data directly to memory buffer, but in case of large xlsx file provider unable to unzip all data to memory buffer and it forced to create temp file on the hard drive. If user hasn't permission to the folder Content.MSO on hard drive mentioned problem appears. Path to folder depends on your enviroment. In my case it is C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.MSO (32-bit driver on 64-bit Windosw Server 2008 R2). So, grant access to Content.MSO for user "IIS AppPool\DefaultAppPool" and problem goes away.



来源:https://stackoverflow.com/questions/40343344/unable-to-read-xlsx-file-through-oledb-with-the-size-more-than-1mb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!