locked
Microsoft.office.interop word and The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

    Question

  • I am using the attached code

     

    Private Sub StartApplicationProcess

        InitialiseObject()

       oWord.Visible = True

       oDoc = oWord.Documents.Open(StrStackPath)

        oWord.Visible = True

    end sub

     

    The variables oWord and oDoc are declared in the class as below attached

     

    Private WithEvents oWord As Word.Application

    Private WithEvents oDoc As Word.Document

     

    The sub InitialiseObject() has the below code

     

    Private Sub InitialiseObject()

            oWord = New Word.Application

    End Sub

     

    Ok, lets start! I am having a very strange issue. I am creating a word document using the documents.add method and I close word using the .Quit method, then I am calling the sub StartApplicationProcess (shown above). On the first instance everything goes well and the document is launch as per my requirements. However when I launch again the document I am having The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) in line "oDoc = oWord.Documents.Open(StrStackPath)" in sub StartApplicationProcess. I can't understand this error since I am still initialising the object oWord. Why he can't find the word to launch the document? Funnily enough, if I declare the oWord and the oDoc inside the sub StartApplicationProcess itself, I will not get the error and the document is open, but I can't afford of declaring a local variable since as shown above the variables are also being used to handle events. I also tried moving the code oWord = New Word.Application from the sub InitialiseObject to sub StartApplicationProcess but vb.net failed again. Some suggested to include the property visible = true after declaring the creation of the object. This also didn't sort out my issue.

     

    This is happening with office 2003.

     

    Your suggestion will be greatly appreciated since I really don't know how to handle this issue.

     

    Thanks

    Further to this I've done so more troubleshooting and here are my results

     

    Noticed that the issue is coming from the variable oWord. As shown below the variable oWord is declared at the top level of the class as Private WithEvents oWord As Word.Application. The word docuement is opening in a normal manner. When it is closed the event is raised and therefore the document is closed. In the StartApplicationProcess the code is getting stuck in the code line oDoc = oWord.Documents.Open(StrStackPath). The rpc server is unavailable error shows that you cannot open a document if the word application is open. In my case the word application is open and visible, and if I watch the oWord variable it shows that it has been defined to open. If I change the oWord.visible = false, the word application will hide. This is another prove that oWord variable has been assigned to the word.application. If I execute the code oWord.Documents.add the error RPC server is again there

     

    If I don't trigger the odoc.close event the program will work normally and it will not stop if I try to open the document for x amount of times.

     

    Do you have any ideas what’s happening here?

    Saturday, April 21, 2007 1:19 PM

All replies

  • hi there

    I am facing exactly the same problem

    did you find the solution for that ... Please guide me how did you resolve this problem

    Regards

    Salman Bashir
    Tuesday, September 04, 2007 11:06 AM
  • Hi,

     

    Did you get any solution for this.

     

    I am getting the same error and also getting error like : object reference not set for an object.

     

    Please help..

     

    Monday, September 24, 2007 9:21 AM
  •  

    hi,

     i want to devolop an application which invoke system infiormation remotely. i have done the following code 

     

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Imports System

    Imports System.Collections

    Imports System.ComponentModel

    Imports System.Data

    Imports System.Drawing

    Imports System.Text

    Imports System.Management

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim options As ConnectionOptions

    options = New ConnectionOptions()

    options.Password = "tependra"

    options.Username = "tependra"

    ' different user name and password:

     

    Dim scope As System.Management.ManagementScope

    scope = New ManagementScope("\\tependra1\root\cimv2", options)

    scope.Connect()

    ' Query system for Operating System information

    Dim query As ObjectQuery

    query = New ObjectQuery("SELECT * FROM Win32_OperatingSystem")

    Dim searcher As ManagementObjectSearcher

    searcher =New ManagementObjectSearcher(scope, query)

    Dim queryCollection As ManagementObjectCollection

    queryCollection = searcher.Get()

    Dim m As ManagementObject

    For Each m In queryCollection

    TextBox1.Text = m("csname")

    TextBox2.Text = m("WindowsDirectory")

    TextBox3.Text = m("Caption")

    TextBox4.Text = m("Version")

    TextBox5.Text = m("Manufacturer")

    Next

     

    End Sub

    End Class

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    But when i run this application this error shown

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

    i can't understand why this program not able to login to the remote machine 

    N.B.:-windows firewall is off in both machine and RPC services are also up on both machine

    Wednesday, November 14, 2007 4:56 AM
  •  

    I had this problem and I solved it to add last line instead of username and password ! I think it work for client.

    But for server use without ConnectionOptions.

     

     

    ConnectionOptions Option= new ConnectionOptions();

    Option.Authority = "NTLMdomainTongue Tiederver.com";

    Thursday, March 27, 2008 11:11 PM
  • Has no one figured out this problem yet?

    I'm having the same problem, only it's with IE instead of MS Word.

    My app can open IE and go to any webpage, but then if I close it and try the exact same action, I get the error message that everyone here is talking about.

    How can it work ONCE but not TWICE?

    I'm totally confused as well.

    Matthew

    Monday, May 12, 2008 10:15 PM
  • When you first launch Word programmatically, it connects to Word via an RPC server. When you close the document, this server gets closed without your application knowing about it.

    The solution is to trap an error and re-initialise your Word object. you will then be able to continue.

    George


    Brisbane
    Wednesday, October 13, 2010 4:50 AM
  • Thanks heaps and heaps.

    This instantly solved the problem for me as well

    Monday, January 17, 2011 5:26 AM