home account info subscribe login search FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Advanced Visual Basic Techniques
(Publisher: John Wiley & Sons, Inc.)
Author(s): Rod Stephens
ISBN: 0471188816
Publication Date: 06/01/97

Search this book:
 
Previous Table of Contents Next


Trouble Shooting

Building a remote automation server offers many opportunities to make mistakes. During the later steps in the process, it can be difficult to find and correct problems. The following list describes some of the most likely problems and suggests ways to correct them:

•  If the server is marked as missing in a client’s references list, remove it from the list, close the list, reopen the list, and select the server again.
•  The most common OLE automation error is Error -2147023143 OLE Automation error. This error usually means the server is unavailable for one of many reasons. Possible reasons include the following:
•  The server machine is not running.
•  The network is not running.
•  The Automation Manager on the server is not running.
•  The wrong server network address was specified in the client’s Remote Automation Connection Manager.
•  The wrong network protocol was specified in the client’s Remote Automation Connection Manager.
•  After a new network address and protocol were specified in the Remote Automation Connection Manager, the Apply button was not clicked.
•  A new server was installed, but the registry entries were not updated by running the new server.
•  If the Remote Automation Connection Manager on the server machine has not authorized remote object creation, the client application will receive the error “Error 70 Permission denied.”
In this case, run the Remote Automation Connection Manager on the server machine and grant access to the server.

Using RegClass

The Visual Basic code for the client and server applications should not need to be changed between steps 2 and 3. The only difference between these steps is in how the client and server interact. These changes are made using the Remote Automation Connection Manager, the Automation Manager, and possibly the client’s references list in the Visual Basic programming environment.

The Client and Server subdirectories of the Ch11\Step3 directory on the compact disk contain the client and server applications. The server application is identical to the server used in step 2. The client application has been modified slightly to demonstrate one more feature of remote server programming.

The RegClass class provides methods that a program can use to manipulate the system registry on a client computer. Before it can use this class, the client must include a reference to it. The RacReg entry should be selected in the project’s References dialog.

RegClass objects provide two public methods. The GetAutoServerSettings function returns information about a server’s registration on the client computer. This function takes as a parameter the program ID of the server class—for example, TimeManager.TimeSetter. It returns a variant containing an array of four values holding the registration information. Table 11.1 describes the values contained in these four entries.

The client application in the Ch11\Step3\Client directory calls the SetCaption subroutine. This routine uses GetAutoServerSettings to decide if the server is local or remote. If it is local, SetCaption sets the caption of the program’s main form to “Local.” Otherwise, it sets the caption to the name of the remote server machine contained in the second value returned by GetAutoServerSettings.

Table 11.1 GetAutoServerSettings Return Values
Entry Number Description
1 True if the server is registered remotely
2 The remote machine name
3 RPC network protocol name
4 RPC authentication level
Sub SetCaption()
Dim reg As New RegClass
Dim result As Variant

    result = reg.GetAutoServerSettings(“TimeManager.TimeSetter”)
    If Not (IsEmpty(result)) Then
     If result(1) Then
         Caption = result(2)
     Else
         Caption = “Local”
     End If
    End If
End Sub

RegClass also provides a public SetAutoServerSettings function. A program can use this function to specify local or remote service, the server computer, and the protocol that should be used for a particular server application. The SetLocalServer subroutine that follows prepares the system to use the local server for TimeManager.TimeSetter. The SetRemoteServer subroutine makes the system use a remote server on the indicated computer.

Private Sub SetLocalServer()
Dim reg As New RegClass

    if reg.SetAutoServerSettings(False, _
        “TimeManager.TimeSetter”) <> 0 _
    Then
         MsgBox “Error making server local.”
    End If
End Sub

Private Sub PrepareRemoteServer(machine_name As String, _
    server_name As String, protocol_name As String)
Dim reg As New RegClass

    if reg.SetAutoServerSettings( _
        True, server_name, , _
        machine_name, protocol_name) <> 0 _
    Then
        MsgBox “Error making server remote.”
    End If
End Sub

For instance, a program could use the PrepareRemoteServer subroutine like this:

PrepareRemoteServer “Beauty”, “TimeManager.TimeSetter”, “ncacn_nb_nb”

This statement indicates that the TimeManager.TimeSetter server should be served remotely by the computer Beauty using the protocol NetBIOS over NetBEUI.

Summary

Creating and installing a client/server application is a complicated process, however implementing the application in three stages can make the process much simpler. First, test the server within the client application. Next, test the client and server in separate instances of Visual Basic running on the same computer. Finally, after the application code is thoroughly tested, install and test the server remotely.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-1999 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.