views:

18

answers:

1

When we try to close excel object, it fails to close to cluster environment. The same is working fine in QA and UAT environment.

public bool KillExcelProcess()
    {
        try
        {
            object misValue = System.Reflection.Missing.Value;
            wbObj.Save();
            wbObj.Close(true, misValue, misValue);
            appC.Workbooks.Close();
            appC.Quit();
            System.Runtime.InteropServices.Marshal.ReleaseComObject(objSheet);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(wbObj);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(appC);
            wbObj = null;
            appC = null;

        }
        catch (Exception ex)
        {
            //throw ex;
        }
        finally
        {
            System.Threading.Thread.Sleep(5000);
            GC.Collect();
        }
        return true;

Calling function

#endregion
        try
        {
            log.Info("CloseExcelService (MeasureSavingsComputeBO) Starts ...");
            exConverter.KillExcelProcess();
            while (true)
            {
                try
                {
                    File.Delete(strFilename);
                    break;
                }
                catch (Exception ex)
                {

                }
            }
A: 

Microsoft recommends against automating Excel server-side here.

You might want to consider a third party component such as SpreadsheetGear for .NET which is 100% safe managed code - no COM Interop problems and no hanging instances of Excel.

You can see live ASP.NET samples with C# and VB source here and download the free trial here.

Disclaimer: I own SpreadsheetGear LLC

Joe Erickson