This document is archived and information here might be outdated.  Recommended version.


How to initialize a GeoDataServer object (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Managing data > Working with feature data > Distributed geodatabases > How to initialize a GeoDataServer object

How to initialize a GeoDataServer object


Summary
A GeoDataServer is an object that references a geodatabase. It is a coarse grained object through which data can be browsed, queried, and extracted, and geodatabase replication can be used. GeoDataServer objects can be initialized locally or accessed remotely from an ArcGIS for Server connection. Because it can be used in many environments, application developers are advised to investigate meeting their requirements using this object. This topic shows the different ways of initializing a GeoDataServer object.

In this topic


Initializing a GeoDataServer object for a local geodatabase

Do the following initialization steps for a local geodatabase:
  1. Cast the GeoDataServer object to the IGeoDataServerInit interface to initialize a GeoDataServer object from a personal or file geodatabase. Call IGeoDataServerInit.InitFromFile with the path of the personal or file geodatabase as a parameter to initialize the object.
  2. Use the following code example to create GeoDataServer objects for a personal geodatabase, file geodatabase, or an ArcSDE geodatabase with a local connection file:
[C#]
// For example, path=@"C:\arcgis\ArcTutor\DatabaseServers\buildings.mdb".
// Or, path=@"C:\arcgis\ArcTutor\DatabaseServers\hazards.gdb".
public IGeoDataServer InitGeoDataServerFromFile(String path)
{
    // Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
    IGeoDataServer geoDataServer=new GeoDataServerClass();
    IGeoDataServerInit geoDataServerInit=(IGeoDataServerInit)geoDataServer;

    // Initialize the GeoDataServer and return it.
    geoDataServerInit.InitFromFile(path);
    return geoDataServer;
}
[VB.NET]
' For example, path=@"C:\arcgis\ArcTutor\DatabaseServers\buildings.mdb".
' Or, path=@"C:\arcgis\ArcTutor\DatabaseServers\hazards.gdb".

Public Function InitGeoDataServerFromFile(ByVal Path As String) As IGeoDataServer
    
    ' Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
    Dim geoDataServer As IGeoDataServer=New GeoDataServerClass()
    Dim geoDataServerInit As IGeoDataServerInit=CType(geoDataServer, IGeoDataServerInit)
    
    ' Initialize the GeoDataServer and return it.
    geoDataServerInit.InitFromFile(Path)
    
    Return geoDataServer
    
End Function

Initializing a GeoDataServer object for an ArcSDE geodatabase

Do the following initialization steps for an ArcSDE geodatabase:
  1. Initialize a GeoDataServer for an ArcSDE geodatabase using a connection string, which is similar to opening a workspace using a connection string.
  2. If a connection file (with a .SDE extension) exists for the geodatabase, create a GeoDataServer object by using the IGeoDataServerInit.InitFromFile method, as shown in the previous code example.
The following code example shows how to initialize an object using a connection string:
[C#]
// For example, connectionString="SERVER=bobmk;INSTANCE=5151;VERSION=sde.DEFAULT;USER=gdb;PASSWORD=gdb".
public IGeoDataServer InitGeoDataServerFromConnectionString(String connectionString)
{
    // Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
    IGeoDataServer geoDataServer=new GeoDataServerClass();
    IGeoDataServerInit geoDataServerInit=(IGeoDataServerInit)geoDataServer;

    // Initialize the GeoDataServer and return it.
    geoDataServerInit.InitFromConnectionString(connectionString);
    return geoDataServer;
}
[VB.NET]
' For example, connectionString="SERVER=bobmk;INSTANCE=5151;VERSION=sde.DEFAULT;USER=gdb;PASSWORD=gdb".

Public Function InitGeoDataServerFromConnectionString(ByVal connectionString As String) As IGeoDataServer
    
    ' Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
    Dim geoDataServer As IGeoDataServer=New GeoDataServerClass()
    Dim geoDataServerInit As IGeoDataServerInit=CType(geoDataServer, IGeoDataServerInit)
    
    ' Initialize the GeoDataServer and return it.
    geoDataServerInit.InitFromConnectionString(connectionString)
    
    Return geoDataServer
    
End Function

Initializing a GeoDataServer object for IWorkspace

If an application has a reference to a workspace (through the IWorkspace interface), a GeoDataServer can be created from it by using the IGeoDataServerInit.InitWithWorkspace method. See the following code example:
[C#]
public IGeoDataServer InitGeoDataServerFromWorkspace(IWorkspace workspace)
{
    // Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
    IGeoDataServer geoDataServer=new GeoDataServerClass();
    IGeoDataServerInit geoDataServerInit=(IGeoDataServerInit)geoDataServer;

    // Initialize the GeoDataServer and return it.
    geoDataServerInit.InitWithWorkspace(workspace);
    return geoDataServer;
}
[VB.NET]
Public Function InitGeoDataServerFromWorkspace(ByVal workspace As IWorkspace) As IGeoDataServer
    
    ' Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
    Dim geoDataServer As IGeoDataServer=New GeoDataServerClass()
    Dim geoDataServerInit As IGeoDataServerInit=CType(geoDataServer, IGeoDataServerInit)
    
    ' Initialize the GeoDataServer and return it.
    geoDataServerInit.InitWithWorkspace(workspace)
    
    Return geoDataServer
    
End Function

Initializing a GeoDataServer object for an ArcGIS for Server GeoData service

A GeoDataServer can be initialized using an ArcGIS for Server GeoData service exposed on the Internet. See the following code example:
[C#]
// For example, url=@"http://jerome/arcgis/services".
// serviceName="FileGDB_GDS".
public IGeoDataServer InitGeoDataServerFromInternetServer(String url, String
    serviceName)
{
    // Create a property set for connection properties.
    IPropertySet propertySet=new PropertySetClass();
    propertySet.SetProperty("URL", url);

    // Connect to the server and get an enumerator for its objects.
    IAGSServerConnectionFactory agsServerConnectionFactory=new
        AGSServerConnectionFactoryClass();
    IAGSServerConnection agsServerConnection=agsServerConnectionFactory.Open
        (propertySet, 0);
    IAGSEnumServerObjectName enumServerObjectName =
        agsServerConnection.ServerObjectNames;
    enumServerObjectName.Reset();

    // Iterate through the objects to locate the GeoData service.
    IAGSServerObjectName serverObjectName=null;
    IGeoDataServer geoDataServer=null;
    while ((serverObjectName=enumServerObjectName.Next()) != null)
    {
        if (serverObjectName.Name == serviceName)
        {
            IName name=(IName)serverObjectName;
            geoDataServer=(IGeoDataServer)name.Open();
            break;
        }
    }

    return geoDataServer;
}
[VB.NET]
' For example, url=@"http://jerome/arcgis/services".
' serviceName="FileGDB_GDS".

Public Function InitGeoDataServerFromInternetServer(ByVal url As String, ByVal serviceName As String) As IGeoDataServer
    
    ' Create a property set for connection properties.
    Dim propertySet As IPropertySet=New PropertySetClass()

    propertySet.SetProperty("URL", url)
        
        ' Connect to the server and get an enumerator for its objects.
        Dim agsServerConnectionFactory As IAGSServerConnectionFactory=New AGSServerConnectionFactoryClass()
        Dim agsServerConnection As IAGSServerConnection=agsServerConnectionFactory.Open(propertySet, 0)
        Dim enumServerObjectName As IAGSEnumServerObjectName=agsServerConnection.ServerObjectNames
        enumServerObjectName.Reset()
        
        ' Iterate through the objects to locate the GeoData service.
        Dim serverObjectName As IAGSServerObjectName=Nothing
        Dim geoDataServer As IGeoDataServer=Nothing
        Do While Not (serverObjectName) Is Nothing
            If serverObjectName.Name=serviceName Then
                Dim Name As IName=CType(serverObjectName, IName)
                geoDataServer=CType(Name.Open(), IGeoDataServer)
                Exit Do
            End If
            serverObjectName=enumServerObjectName.Next()
        Loop
        
        Return geoDataServer
        
    End Function
Initializing GeoDataServer objects for GeoData services exposed through a local network is similar to those exposed through the Internet, with only the connection properties changing slightly. See the following code example:
[C#]
// For example, machineName="jerome".
// serviceName="FileGDB_GDS".
public IGeoDataServer InitGeoDataServerFromNetworkServer(String machineName, String
    serviceName)
{
    // Create a property set for connection properties.
    IPropertySet propertySet=new PropertySetClass();
    propertySet.SetProperty("Machine", machineName);

    // Connect to the server and get an enumerator for its objects.
    IAGSServerConnectionFactory agsServerConnectionFactory=new
        AGSServerConnectionFactoryClass();
    IAGSServerConnection agsServerConnection=agsServerConnectionFactory.Open
        (propertySet, 0);
    IAGSEnumServerObjectName enumServerObjectName =
        agsServerConnection.ServerObjectNames;
    enumServerObjectName.Reset();

    // Iterate through the objects to locate the GeoData service.
    IAGSServerObjectName serverObjectName=null;
    IGeoDataServer geoDataServer=null;
    while ((serverObjectName=enumServerObjectName.Next()) != null)
    {
        if (serverObjectName.Name == serviceName)
        {
            IName name=(IName)serverObjectName;
            geoDataServer=(IGeoDataServer)name.Open();
            break;
        }
    }

    return geoDataServer;
}
[VB.NET]
' For example, machineName="jerome".
' serviceName="FileGDB_GDS".

Public Function InitGeoDataServerFromNetworkServer(ByVal machineName As String, ByVal serviceName As String) As IGeoDataServer
    
    ' Create a property set for connection properties.
    Dim propertySet As IPropertySet=New PropertySetClass()

    propertySet.SetProperty("Machine", machineName)
        
        ' Connect to the server and get an enumerator for its objects.
        Dim agsServerConnectionFactory As IAGSServerConnectionFactory=New AGSServerConnectionFactoryClass()
        Dim agsServerConnection As IAGSServerConnection=agsServerConnectionFactory.Open(propertySet, 0)
        Dim enumServerObjectName As IAGSEnumServerObjectName=agsServerConnection.ServerObjectNames
        enumServerObjectName.Reset()
        
        ' Iterate through the objects to locate the GeoData service.
        Dim serverObjectName As IAGSServerObjectName=Nothing
        Dim geoDataServer As IGeoDataServer=Nothing
        Do While Not (serverObjectName) Is Nothing
            If serverObjectName.Name=serviceName Then
                Dim Name As IName=CType(serverObjectName, IName)
                geoDataServer=CType(Name.Open(), IGeoDataServer)
                Exit Do
            End If
            serverObjectName=enumServerObjectName.Next()
        Loop
        
        Return geoDataServer
        
    End Function






To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine: Geodatabase Update