Microsoft ACE OLEDB connection creating empty Excel when there are 166,110 rows

假装没事ソ 提交于 2019-12-01 01:04:28
Per

I am not sure about your application environment, but I have seen this when generating Excel files from an ASP.NET app.

Once the amount of data exceeds a certain size (~1 MB in my experience), the provider will attempt to create a temp file while generating the output. I have come across this issue using the 32-bit provider on 64-bit systems. If you are running under a service account with this configuration then the location where these files are created is

C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.MSO

This location, however, is only accessible to administrators and SYSTEM by default, and if the provider is running under a non-privileged account and is unable to create the temp file it will fail silently and just return its default "empty file" with the A266FF2A662E84b639DA worksheet.

What you need to do is grant the account of the application that runs under (for example Network Service or IIS AppPool\) read/execute/list contents permissions along the path "C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\Windows\Temporary Internet Files" and then full access to the Content.MSO folder itself.

If the provider matches the bitness of your system then I suspect you need to perform the process above for C:\Windows\System32\config\systemprofile\AppData\Local\Microsoft\Windows\Temporary Internet Files\Content.MSO instead, although I have never tested this.

I want to extend my thanks to sysinternals for providing procmon that helped me troubleshoot this issue.

One of the employees at my company ran across this problem today. The solution was simple: She had only 20MB free space left on C: - If you free up enough space on your system drive, it should solve the problem.

Windows Server 2012R2 Check also if folder INetCache exists and this folder has full perimissions C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\Windows\INetCache

After 10 hours I found the solution.

Every 1000 rows we have to close and reopen the connection.

Sample is here.

string createTable = "Create Table [Sheet_X] (field1 char(255), field2 char(255),field3 char(255));";
OleDbCommand cmd = new OleDbCommand(createTable, conn);
conn.Open();
cmd.ExecuteNonQuery();
var counter = 0;
foreach (var item in items)
{
    if (conn.State == ConnectionState.Closed)
        conn.Open();
    string insertdata = "insert into [Sheet_X] (field1,field2,field3) values('value1','value2','value3');";
    counter++;
    if (counter >= 1000)
    {
        counter = 0;
        conn.Close();
    }
}

If it still don't work after tried all above solutions, try this one, it worked for me:

In the "Advanced settings" of your IIS Application Pool, Change the value of "Load User Profile" from "False" to "True".

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