none
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

    Question

  • Hi Chaps,

     

    I'm using this snipped code in Visual Basic 2005 with one problem.

    On my development PC Win XP-SP2; Visual Basic 2005; Office 2003-SP2 this code is working well. On a different PC with same configuration (except VS 2005) I'm running into an error called: "The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)". The goal of my code is just to analyse to page no in a Word document.

     

    Does someone has an idea what coused the problem?

     

    Imports Word = Microsoft.Office.Interop.Word

     

    Module mdl_TEST


       Public WordApp As Word.Application 'Class
       Public WordDoc As Word.Document

     

       Public Function TEST(ByVal sPfad As String) As Short
          Dim m As Object = System.Reflection.Missing.Value
          Dim PageNo As Short

     

          Try
             WordApp = New Word.Application
             WordApp.Visible = False

             WordDoc = WordApp.Documents.Open(sPfad, m, False, m, m, m, m, m, m, m, m, m)

             'determine Page#
             PageNo = WordDoc.ComputeStatistics(Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages)

             WordDoc.Close()

             WordDoc = Nothing

             WordApp.Quit(m, m, m)

            
          Catch ex As Exception
             'error routine...

          End Try

     

       End Function

     

    End Module

    Tuesday, October 16, 2007 6:50 PM

Answers

  •  Hans-Joachim wrote:

    About your Q: Do you have any idea on which line the code is failing?

    My DEBUG log shows me the line:

    WordDoc = WordApp.Documents.Open(sPfad, m, False, m, m, m, m, m, m, m, m, m)

     

    The whole PIA will not be installed via SETUP, but just the word portion of it.

    I will install the PIA for Office 2003 manually on target system and see what happen.

     

    I'll be interested to see if there is a difference using the PIAs that come with the application.

     

    For the failed code line: interesting... Try setting that third parameter to Missing, as well. Or, since this is VB, get rid of all of them except sPfad. If there is a conflict in the PIAs you used to develop the app, and the version of Word installed on the target machine, dropping these "unnecessary" parameters might make a difference. (Note: you may need to set Option Strict Off for this test.)

    Thursday, October 18, 2007 5:25 PM
  • Hello Cindy and Hans,

     

    from my expirience you should exclude the

    PIA and all Office dlls from your setup.

     

    Otherwise when you uninstall your application from the target machine, the Office installation becomes corrupted.

     

    You should download the Office PIA redistributables and include it as prerequisite in your setup application.

    To make the PIA's available for the Bootstrapper, you have to include the package definitions for it in your Visual Studio Packages folder.

     

     

    You can finde the PIA's here:

    2003:  http://www.microsoft.com/downloads/info.aspx?na=22&p=1&SrcDisplayLang=en&SrcCategoryId=&SrcFamilyId=&u=%2fdownloads%2fdetails.aspx%3fFamilyID%3d3c9a983a-ac14-4125-8ba0-d36d67e0f4ad%26DisplayLang%3den

     

    2007: http://www.microsoft.com/downloads/info.aspx?na=22&p=2&SrcDisplayLang=en&SrcCategoryId=&SrcFamilyId=&u=%2fdownloads%2fdetails.aspx%3fFamilyID%3d59daebaa-bed4-4282-a28c-b864d8bfa513%26DisplayLang%3den

     

    To get the Packages definitions, install the sample that comes from this article.

    http://msdn2.microsoft.com/en-us/library/bb332051.aspx

     

    Just my expirience.

     

    Hope this helps,

    greets, Helmut

     

     

     

    Thursday, October 18, 2007 5:35 PM
  • Hello Cindy and Helmut,

     

    the work is done (it seems to be - the last tests were successfully).

     

    To be fair...here is the updated snipped code.

    Code Block

    Option Strict Off

    Imports Word = Microsoft.Office.Interop.Word

     

    Module mdl_TEST
       Public WordApp As Word.Application
       Public WordDoc As Word.Document

     

       Public Function TEST(ByVal sPfad As String) As Short
          Dim PageNo As Short

          Try
             WordApp = New Word.Application
             WordApp.Visible = False

     

             WordDoc = WordApp.Documents.Open(sPfad)

     

             'determine Page#
             PageNo = WordDoc.ComputeStatistics(Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages)

     

             WordDoc.Close()
             WordDoc = Nothing

     

             WordApp.Quit()
             WordApp = Nothing

            
          Catch ex As Exception
             'error routine...

          End Try

     

       End Function

     

    End Module

     

     

    In addition: I excluded the Word portion (about PIA) in my setup and it is now part of the Bootstrapper.

    Thanks a lot for your time you did spend.

     

    -Hans

     

     

    Saturday, October 20, 2007 7:25 AM

All replies

  • Does this happen every time you try to run it, or does it work the first time?

     

    The error you report is typical when automating Word and object variables aren't properly released. You don't set WordApp = Nothing after you Quit the application.

     

    Wednesday, October 17, 2007 7:39 AM
  • Yes, every time I get this error message.

    I added a snipped code here, but the seq. is according the real in my apps.

     

    1. Start my apps.

    2. follow the code...

    WordApp = New Word.Application --- Assigning WordApp

    WordDoc = WordApp.Documents.Open ----------+

    WordDoc = Nothing --------------------+--- LOOPing here

    WordApp.Quit(m, m, m) ---At the end of the process

    --- mea culpa I didn't use WordApp = Nothing

    3. Closing my apps.

     

    But any way it shouldn't be matter (WordApp = Nothing) if I closing the apps and restart it for next process.

     

     

    Wednesday, October 17, 2007 12:24 PM
  • In that case, I recommend you go with this question to the office.developer.automation newsgroup. This forum is specifically targeted at the VSTO technology, and not at general Office automation. The error you reported was known to me, under the described circumstances, but if something else is causing it, you'll have a better chance getting answers in the newsgroup interface.

    http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.office.developer.automation&lang=en&cr=US

     

    You might also try searching the Knowledge Base on the phrase: RPC server

     

    Wednesday, October 17, 2007 12:37 PM
  • O.K. already posted.

    Wednesday, October 17, 2007 5:01 PM
  • Hello HAL,

     

    do you have installed the Primary Interop Assemblies (PIA) for Office 2003 on the Target machine ?

     

    Maybe that's the problem.

     

    Hope this helps,

    greets, Helmut

    Wednesday, October 17, 2007 8:05 PM
  • Helmut,

     

    because I have added the reference "Microsoft.Office.Interop.Word" into my project, the installer will automatically include (and it did) the required files into the setup portion of the project. Therefore an separat installation of PIA on target system is not necessary.

     

    -Hans

    Wednesday, October 17, 2007 9:18 PM
  •  Hans-Joachim wrote:

    because I have added the reference "Microsoft.Office.Interop.Word" into my project, the installer will automatically include (and it did) the required files into the setup portion of the project. Therefore an separat installation of PIA on target system is not necessary.

    Hans: Which version of Word did you develop against, and which version is installed on the target machine?

    Thursday, October 18, 2007 2:18 PM
  • Cindy,

     

    I'm using Win XP - SP 2 - DE --- Office 2003 - SP2 - DE on development PC. The target PC has same version installed.

    This week I did upgrade to Office 2003 - SP3 - DE, but nothing happen (problem still exists)

     

    -Hans

    Thursday, October 18, 2007 4:06 PM
  •  Hans-Joachim wrote:

    I'm using Win XP - SP 2 - DE --- Office 2003 - SP2 - DE on development PC. The target PC has same version installed.

    This week I did upgrade to Office 2003 - SP3 - DE, but nothing happen (problem still exists)

     

    Thanks for your patience - I see you had that in your first message, but my brain "ticked" on your statement about the IAs and setup. I'm still not clear on exactly what's with that (whether you're installing the PIAs d/l from Microsoft or a set of IAs you've generated using TlbImp). Normally, for Office 2003, the recommendation is that your application should not install the PIAs, but that the user should run Office setup again to do so, once the .NET Framework is present. Something to consider, anyway...

     

    I keep going back to your code snippet in the first message. The function you show us doesn't return anything, but I assume that's due to the snipping...

     

    Do you have any idea on which line the code is failing? Is it when the Word application should be started, or at a different point? And does it make any difference if you set the application to be Visible? (Word can do really odd things when its app window is not visible. And generally it will have difficulty computing the number of pages if it can't layout the document visibly, on screen.)

     

    I also notice that you're assigning the result to a variable of type Short. In its native VBA, ComputeStatistics is of Type LONG; in the .NET Framework that's equivalent to an Int32 (Integer). I wouldn't think that would be an issue for VB.NET (althoug it definitely would be for C#), but you never know...

    Thursday, October 18, 2007 4:36 PM
  • Cindy,

     

    this was my fault...it is defined as integer right now.

    Dim PageNo As Integer

     

    In VB the WordDoc.ComputeStatistics is set to INTEGER (I checked it right now)

    PageNo = WordDoc.ComputeStatistics(Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages)

     

     

    About your Q: Do you have any idea on which line the code is failing?

    My DEBUG log shows me the line:

    WordDoc = WordApp.Documents.Open(sPfad, m, False, m, m, m, m, m, m, m, m, m)

     

    The whole PIA will not be installed via SETUP, but just the word portion of it.

    I will install the PIA for Office 2003 manually on target system and see what happen.

     

    -Hans

    Thursday, October 18, 2007 5:04 PM
  •  Hans-Joachim wrote:

    About your Q: Do you have any idea on which line the code is failing?

    My DEBUG log shows me the line:

    WordDoc = WordApp.Documents.Open(sPfad, m, False, m, m, m, m, m, m, m, m, m)

     

    The whole PIA will not be installed via SETUP, but just the word portion of it.

    I will install the PIA for Office 2003 manually on target system and see what happen.

     

    I'll be interested to see if there is a difference using the PIAs that come with the application.

     

    For the failed code line: interesting... Try setting that third parameter to Missing, as well. Or, since this is VB, get rid of all of them except sPfad. If there is a conflict in the PIAs you used to develop the app, and the version of Word installed on the target machine, dropping these "unnecessary" parameters might make a difference. (Note: you may need to set Option Strict Off for this test.)

    Thursday, October 18, 2007 5:25 PM
  • Hello Cindy and Hans,

     

    from my expirience you should exclude the

    PIA and all Office dlls from your setup.

     

    Otherwise when you uninstall your application from the target machine, the Office installation becomes corrupted.

     

    You should download the Office PIA redistributables and include it as prerequisite in your setup application.

    To make the PIA's available for the Bootstrapper, you have to include the package definitions for it in your Visual Studio Packages folder.

     

     

    You can finde the PIA's here:

    2003:  http://www.microsoft.com/downloads/info.aspx?na=22&p=1&SrcDisplayLang=en&SrcCategoryId=&SrcFamilyId=&u=%2fdownloads%2fdetails.aspx%3fFamilyID%3d3c9a983a-ac14-4125-8ba0-d36d67e0f4ad%26DisplayLang%3den

     

    2007: http://www.microsoft.com/downloads/info.aspx?na=22&p=2&SrcDisplayLang=en&SrcCategoryId=&SrcFamilyId=&u=%2fdownloads%2fdetails.aspx%3fFamilyID%3d59daebaa-bed4-4282-a28c-b864d8bfa513%26DisplayLang%3den

     

    To get the Packages definitions, install the sample that comes from this article.

    http://msdn2.microsoft.com/en-us/library/bb332051.aspx

     

    Just my expirience.

     

    Hope this helps,

    greets, Helmut

     

     

     

    Thursday, October 18, 2007 5:35 PM
  • Hi Cindy,

    Hi Helmut,

     

    now I made the following changes in my code:

    Option Strict Off...was done already before

    ...

    WordDoc = WordApp.Documents.Open(sPfad)

     

    And last but not least I did exclude the Word portion in my setup. If this is the issue for the problem I will configure my Bootstrapper.

    Now I do follow up this thread on Saturday --- I'm on the road tomorrow.

     

    -Hans

    Thursday, October 18, 2007 6:18 PM
  • Hello Cindy and Helmut,

     

    the work is done (it seems to be - the last tests were successfully).

     

    To be fair...here is the updated snipped code.

    Code Block

    Option Strict Off

    Imports Word = Microsoft.Office.Interop.Word

     

    Module mdl_TEST
       Public WordApp As Word.Application
       Public WordDoc As Word.Document

     

       Public Function TEST(ByVal sPfad As String) As Short
          Dim PageNo As Short

          Try
             WordApp = New Word.Application
             WordApp.Visible = False

     

             WordDoc = WordApp.Documents.Open(sPfad)

     

             'determine Page#
             PageNo = WordDoc.ComputeStatistics(Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages)

     

             WordDoc.Close()
             WordDoc = Nothing

     

             WordApp.Quit()
             WordApp = Nothing

            
          Catch ex As Exception
             'error routine...

          End Try

     

       End Function

     

    End Module

     

     

    In addition: I excluded the Word portion (about PIA) in my setup and it is now part of the Bootstrapper.

    Thanks a lot for your time you did spend.

     

    -Hans

     

     

    Saturday, October 20, 2007 7:25 AM