在服务器端获取System.Runtime.InteropServices.COMException错误生成的Excel [英] Getting System.Runtime.InteropServices.COMException Error in Server Side Generated Excel

查看:3278
本文介绍了在服务器端获取System.Runtime.InteropServices.COMException错误生成的Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Web应用程序生成的Excel US preadsheets并运行在服务器端的宏。 ,然后将其通过电子邮件发送给不同的个体。这是我们正在转变,但仍然支持我们,我们提供为IIS中的网站新的应用程序的传统报表样式的一部分。

We have a web application that generates excel spreadsheets and run macros on the server side. It then sends them to different individuals via email. It is a part of a legacy reporting style which we are transitioning but still supporting on our new application which we delivered as a website in IIS.

我知道这是一个不好的做法,做办公自动化,因为我看到了来自微软的信息,这是不支持的。它也表示在这里<一个答案href="http://stackoverflow.com/questions/14716047/opening-excel-error-system-runtime-interopservices-comexception-0x80080005-r">opening Excel中的错误信息:System.Runtime.InteropServices.COMException(0x80080005):检索COM类工厂组件具有CLSID

I know it is a bad practice to do Office Automation as I saw info from Microsoft that this is not supported. It is also indicated in the answer here opening excel error: System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID

不管怎么说,以缩短在批处理情况下,可以从3至300报告发送给不同的人产生生成的Excel报表的故事。该报告生成正常工作,直到它击中周围的15至20项则胡扯出来,它给了我下面

Anyways to cut the story short the excel reports are generated in a batch scenario which can generate from 3 to 300 reports sending to different people. The report generation works fine until it hits around the 15 to 20th item then it craps out, it gives me the error below

System.Runtime.InteropServices.COMException (0x80080005): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
   at System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)
   at System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)
   at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType, Object[] props, Boolean bNewObj)
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at Ci.Infrastructure.Reporting.ReportProviderExcel.RunReport()

这可能是错的?第一个报告出来了成功,我知道它不是Excel的模板,当我重新运行一遍所有失败的人会继续成功地监守,并在15到20日的报告获取生成再次引发错误。

What might be wrong? The first reports came out successful and I know its not the excel templates becuase when I rerun it again all the failed ones will continue successfully and when the 15 to 20th report gets generated it throws the error again.

更新:我们知道是在自找麻烦,但我需要一个解决方案来解决该问题。请记住,这是对传统的东西,我们将停止支持的未来,但在过渡时期,我们需要它的工作。

我们试图序列化仍然无法正常工作。 我们试图睡觉生成Excel报表,当它击中一个COM异常的线程,它的工作原理,但是这不是一个优雅的结果。任何一个优秀的解决方案来解决这个问题将被授予奖金。

We tried serializing still does not work. We tried sleeping the thread that generates the excel report when it hits a COM Exception, it works but this is not an elegant result. Any good solution to address this issue will be granted the bounty.

另一个更新:

通过在f​​inally块这样解决了。

Solved by doing this on the finally block

finally
{
    if (dataWorksheet != null)
    {
        Marshal.ReleaseComObject(dataWorksheet);
    }

    if (worksheets != null)
    {
        Marshal.ReleaseComObject(worksheets);
    }

    if (workbook != null)
    {
        workbook.Close(false);
        Marshal.ReleaseComObject(workbook);
    }

    if (workbooks != null)
    {
        workbooks.Close();
        Marshal.ReleaseComObject(workbooks);
    }

    if (excel != null)
    {
        excel.Quit();
        Marshal.ReleaseComObject(excel);
    }
}

像什么MarkWalls说接近每一个Excel的情况下,作为一个工作单元从而彻底清除出Excel进程才再次使用。

Like what MarkWalls said close each of the excel instances as a unit of work which completely clears out EXCEL process before it is used again.

推荐答案

我有一个问题,就像这一点。以上这些问题的答案都是正确的一样 - 你可能根本未垃圾回收的Excel实例脱胶了服务器池

I had a problem much like this. The answers above are like correct - you probably have essentially a pool of un-garbage collected excel instances gumming up the server.

我为它的解决办法是非常小心地打开创建闭每个Excel的情况下,作为一个工作单位的,然后检查,看看是否有任何的Excel实例保留在服务器进程。它只是通过所有的人一个又一个这样的夜晚,并让他们在一个仓库发出早上。

My solution for it was to very carefully open-create-close each of the excel instances as a unit of work, then check to see if any of the excel instances remained on the server process. It just went through all of them one by one like that at night and had them in a repository to send out in the morning.

另一种认为,我们尽力了,但不得不到底要不要使用,是创造的CSV文件,而不是Excel文件。如果你只是需要的数据,然后CSV更加轻巧。我们曾经复杂的公式中的工作簿,以及刚刚离不开完成。

Another thought that we tried, but had to not use in the end, was creating CSV files rather than excel files. If you just need the data, then CSV is much more lightweight. We had complicated formulas in the workbooks as well that just couldn't be done without.

这篇关于在服务器端获取System.Runtime.InteropServices.COMException错误生成的Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆