Office automation throws exception upon initialization
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Office automation throws exception upon initialization

  1. #1
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    448

    Question Office automation throws exception upon initialization

    I have a webapp where the user can make excel sheets. It's been working fine for some time, but suddenly things start to fail.

    When I initialize my Excel process I get an exception.

    Code:
    Code:
                xlApp = new Excel.Application();
                if (xlApp == null)
                    m_log.WriteLogLine("xlApp is null", LogLevel.High, LogType.Info);
              
                xlApp.DisplayAlerts = false;
                xlWorkBook = xlApp.Workbooks.Add(misValue);
    I get the exception:
    [OutOfMemoryException: Insufficient memory to continue the execution of the program.]
    Microsoft.Office.Interop.Excel.Workbooks.Add(Object Template)

    I've checked that there's enough ram and hhd space, and that we have access to our file destination (even though we're far from the place where we actually try to write to the disk).

    Anyone who knows what may cause this and how to fix it?

    Edit: I use Office 2013
    Last edited by Lars_V_J; July 26th, 2014 at 02:49 AM.

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,985

    Re: Office automation throws exception upon initialization

    Talk to the ISP and ask them. Sounds like a setting that can be changed.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    448

    Re: Office automation throws exception upon initialization

    It is on an intranet...

    I even ran the browser on the server

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,985

    Re: Office automation throws exception upon initialization

    Check the logs on the server, then.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,359

    Re: Office automation throws exception upon initialization

    If you are not cleaning up the objects, you may be holding onto COM references, so clean up after yourself.

    Wrap the xlApp call inside a using block.

    Code:
    using( var xlApp = new Excel.Application())
    {
      if (xlApp == null)
        m_log.WriteLogLine("xlApp is null", LogLevel.High, LogType.Info);
              
        xlApp.DisplayAlerts = false;
        xlWorkBook = xlApp.Workbooks.Add(misValue);
    }
    If Excel.Application doesn't support the IDisposable interface, then explicitly call Close() (or read the documentation on what to call).

    Do the same for xlWorkBook.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center