none
“There is insufficient memory. Save the document now.” error while opening word 2003 document

    Question

  • Hi, I have developed one windows service through which I am trying to open an word document. But when service tries to open document, it logs following error "There is insufficient memory. Save the document now." If I run the same program as normal windows application, it works fine but problem comes only when I try to run the program as windows service.

    I tried to google this problem, but there arent many answers about this problem. Is there any way to increase the memory limit for windows service or process? Something like in Java world, where we can specify memory limit while executing java class java -Xmx800M. Is there something similar for windows processes?

    Does anyone knows how to solve this problem? I am using C#, .net framework 2.0 and office 2003 for development.


    Thanks and Regards, Chandrashekhar
    Wednesday, September 15, 2010 11:13 AM

Answers

  • Hi chandrashekar

    For different ways of starting Office apps, see this blog article

    http://blogs.msdn.com/b/andreww/archive/2008/11/30/starting-or-connecting-to-office-apps.aspx

    Starting a process, you use the commandline, and Word accepts a file name as part of a command line to open a file. After the commandline to the winword.exe file type a space then put the full file name (with path). Put it in quotes if it contains spaces.

    At this point, it won't let you manipulate the document (you have no "in" to the Word interop), but that will at least tell you if the document can be started.

    To pick up the Word application after that point, you'd need to use GetActiveObject.

    For the code you posted, I recommend - for testing purposes - setting all the parameters to Type.Missing except the file name. Furthermore...

    <<thisApplication is an object of type Application >>

    Mmm. I assume this is actually typed to Word.Application?


    Cindy Meister, VSTO/Word MVP
    Monday, September 20, 2010 8:30 AM
    Moderator

All replies

  • Hi shekhar

    You asked me to look at this, so here I am...

    Probably, you haven't gotten a reply because no one knows :-) This happens with any/all documents, not just a particular one? And you're only trying to open it, not do anything else?

    Usually, this message crops up when a program is doing a lot of formatting or table-editing. The standard steps are to perform a Save at regular intervals and clear the Undo buffer. But if you're only opening documents, then obviously it's something else.

    What is a "windows service", exactly?


    Cindy Meister, VSTO/Word MVP
    Monday, September 20, 2010 6:12 AM
    Moderator
  • Thanks a lot Cindy for help.

    This exception occures for all the documents which my windows service tries to open. I am able to open those same documents manually without any problem.

    My "windows service"

    1) creates starts one thread which runs in a loop looking for new word documents.

    2) As soon as it finds new document, it opens that document

    3) Reads document sentence by sentence 

    4) Writes formatting information of that sentence like font size, bold, italics, etc. in new text file and

    5) Close the document.

    I am not really modifying the original document. I get this exception only when I call this application from my windows service. If I run this application as a console application, it works fine without any exception.

    Please let me know if you need more details about the problem.


    Thanks and Regards, Chandrashekhar
    Monday, September 20, 2010 7:16 AM
  • Hi Chandrashekhar

    See, I don't know what a "windows service" is, technologically speaking :-)

    It seems pretty obvious the problem has to do with how it interacts with the COM application. The Office apps are designed for user interaction, not for "server side" use or "remoting". I do know (on an intellectual level!) that for some "remoting" uses it's necessary to work over DCOM, but I'm not familiar with any of the details. You might try looking into that, to see if it's relevant.

    You also don't show us the code involved. If it's something like Word.Application wdApp = new Word.Application ; wdApp.Documents.Open(//etc.); then perhaps it will work better to use the command line (Process namespace).

    Or it might even be better to work with the file without opening it in Word. With word 2003 I suppose you have to support the binary *.doc file format. But that specification is now in the public domain:

    Office binary file formats
    - Forum
    - obtaining

    Cindy Meister, VSTO/Word MVP
    Monday, September 20, 2010 7:26 AM
    Moderator
  • Hi Cindy,

    Here is the code snippet for opening word document

     

    objDocument = new Document();
    
    Object confirmConversions = false;
    Object readOnly = true;
    Object addToRecentFiles = Type.Missing;
    Object passwordDocument = Type.Missing;
    Object passwordTemplate = Type.Missing;
    Object revert = Type.Missing;
    Object writePasswordDocument = Type.Missing;
    Object writePasswordTemplate = Type.Missing;
    Object format = Type.Missing;
    Object encoding = Type.Missing;
    Object visible = false;
    Object openConflictDocument = false;
    Object openAndRepair = false;
    Object documentDirection = Type.Missing;
    Object noEncodingDialog = Type.Missing;
    object missing = Type.Missing;
    object objFile = strFilename;
    
    // thisApplication is an object of type Application which is static member in this class
    objDocument = thisApplication.Documents.Open(ref objFile,
    ref confirmConversions,
    ref readOnly,
    ref addToRecentFiles,
    ref passwordDocument,
    ref passwordTemplate,
    ref revert,
    ref writePasswordDocument,
    ref writePasswordTemplate,
    ref format,
    ref encoding,
    ref visible,
    ref openConflictDocument,
    ref openAndRepair,
    ref documentDirection,
    ref noEncodingDialog);
    
    objDocument.Activate();
    

     How to open and iterate through word document using command prompt?

     


    Thanks and Regards, Chandrashekhar
    Monday, September 20, 2010 7:39 AM
  • Hi chandrashekar

    For different ways of starting Office apps, see this blog article

    http://blogs.msdn.com/b/andreww/archive/2008/11/30/starting-or-connecting-to-office-apps.aspx

    Starting a process, you use the commandline, and Word accepts a file name as part of a command line to open a file. After the commandline to the winword.exe file type a space then put the full file name (with path). Put it in quotes if it contains spaces.

    At this point, it won't let you manipulate the document (you have no "in" to the Word interop), but that will at least tell you if the document can be started.

    To pick up the Word application after that point, you'd need to use GetActiveObject.

    For the code you posted, I recommend - for testing purposes - setting all the parameters to Type.Missing except the file name. Furthermore...

    <<thisApplication is an object of type Application >>

    Mmm. I assume this is actually typed to Word.Application?


    Cindy Meister, VSTO/Word MVP
    Monday, September 20, 2010 8:30 AM
    Moderator
  • Hi Chandrashekar,

    I am also facing similar problem when I am doing a mail merge using a windows service while the same does not happen when running as a stand alone application.

     

    I hope you had a solution to your porbem. If so, please share it and make my day.

    Environment: Win 2008 R2, Office 2003, Adobe 9.0 Pro.

     

    Thanks in Advance...

    Monday, May 09, 2011 3:03 PM
  • Thanks for your response Chandrashekar. I really appreaciate!
    Monday, May 09, 2011 9:03 PM
  • Hi,

     

    I am also facing the same issue.

    I try to save a Word Document using Windows application executing through a service, but the error comes as saying - "There is insufficient memory. Save the document now".

     

    The application runs great when executed on a stand alone manner, but as soon as called through a service, the error comes up.

    I tried executing the service from another system and it runs good on the other machine, but it fails to execute on the machine it needs to be executed.

    Present Machine config:

    Microsoft Windows 2003, Word 2003 for development

     

    If someone has the solution to the issue, please share it with me.

     

    Thanks in advance.


    Tuesday, August 16, 2011 1:08 PM
  • I spend good enough of time and finally resolved this.
    Stop your service. Ceate the following folders on the machine you are running the service.  First one is for 64 bit O/S only and you have not mentioned if 2003 is 32 or 64 bit. Start the service.
          C:\Windows\SysWOW64\config\systemprofile\
          C:\Windows\System32\config\systemprofile\ 
    Tuesday, August 16, 2011 1:36 PM
  • Hey,

     

    Thanks a lot. The problem is solved.

    I'm facing another issue in the process:

    Error being-

    The remote procedure call failed. (Exception from HRESULT: 0x800706BE)

    Can someone please tell me what this error refers to and how we can avoid the same.

     

    Thanks in advance.

    Thursday, August 18, 2011 9:12 AM
  • It is not clear from the post where exactly the error is occuring, leaving it to a wide scope. I did come across similar error but solution might different in your case unless it is same issue. In my case atleast, Microsoft .Ne Framework 4.0 was involved which resolved with update to Framework 4.0.3

    Microsoft link for download and details: http://support.microsoft.com/kb/2600211

    Wednesday, April 03, 2013 8:30 PM