How to initialize a GeoDataServer object


Summary A GeoDataServer is an object that references a geodatabase. It is a coarse-grained object through which you can browse, query, extract data, and use geodatabase replication. GeoDataServer objects can be initialized locally or accessed remotely from an ArcGIS Server connection. Because it can be used in so many environments, application developers are advised to investigate meeting their requirements using this object.

This article shows the different ways of initializing a GeoDataServer object.

In this topic


Initializing a GeoDataServer object for a local geodatabase

  • To initialize a GeoDataServer object from a personal or file geodatabase, the GeoDataServer object should first be cast to the IGeoDataServerInit interface. IGeoDataServerInit.InitFromFile can then be called, with the path of the personal or file geodatabase as a parameter, to initialize the object.
  • The following code can be used to create GeoDataServer objects for a personal geodatabase, a file geodatabase, or an ArcSDE geodatabase with a local connection file:
[Java]
// For example, path = "C:\arcgis\ArcTutor\DatabaseServers\buildings.mdb"
// Or, path = "C:\arcgis\ArcTutor\DatabaseServers\hazards.gdb"
static IGeoDataServer initGeoDataServerFromFile(String path)throws Exception{
    // Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
    IGeoDataServer geoDataServer = new GeoDataServer();
    IGeoDataServerInit geoDataServerInit = (IGeoDataServerInit)geoDataServer;
    // Initialize the GeoDataServer and return it.
    geoDataServerInit.initFromFile(path);
    return geoDataServer;
}

Initializing a GeoDataServer object for an ArcSDE geodatabase

  • A GeoDataServer for an ArcSDE geodatabase can be initialized using a connection string, much in the same way a workspace can be opened using a connection string.
  • If a connection file (one with a .SDE extension) exists for the geodatabase, a GeoDataServer object can be created by using the IGeoDataServerInit.InitFromFile method, as shown in the previous example.
  • The following code example shows how to initialize an object using a connection string:
[Java]
// For example, connectionString = "SERVER=bobmk;INSTANCE=5151;VERSION=sde.DEFAULT;USER=gdb;PASSWORD=gdb"
static IGeoDataServer initGeoDataServerFromConnectionString(String connectionString)
    throws Exception{
    // Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
    IGeoDataServer geoDataServer = new GeoDataServer();
    IGeoDataServerInit geoDataServerInit = (IGeoDataServerInit)geoDataServer;
    // Initialize the GeoDataServer and return it.
    geoDataServerInit.initFromConnectionString(connectionString);
    return geoDataServer;
}

Initializing a GeoDataServer object for an IWorkspace

[Java]
static IGeoDataServer initGeoDataServerFromWorkspace(IWorkspace workspace)throws
    Exception{
    // Create the GeoDataServer and cast to the the IGeoDataServerInit interface.
    IGeoDataServer geoDataServer = new GeoDataServer();
    IGeoDataServerInit geoDataServerInit = (IGeoDataServerInit)geoDataServer;
    // Initialize the GeoDataServer and return it.
    geoDataServerInit.initWithWorkspace(workspace);
    return geoDataServer;
}

Initializing a GeoDataServer object for an ArcGIS Server GeoData Service

  • A GeoDataServer can be initialized using an ArcGIS Server GeoData Service exposed on the Internet. See the following code:
[Java]
// For example, url = @"http://jerome/arcgis/services"
// serviceName = "FileGDB_GDS"
static IGeoDataServer initGeoDataServerFromInternetServer(String url, String
    serviceName)throws Exception{
    // Create a property set for connection properties.
    IPropertySet propertySet = new PropertySet();
    propertySet.setProperty("URL", url);
    // Connect to the server and get an enumerator for its objects.
    IAGSServerConnectionFactory agsServerConnectionFactory = new
        AGSServerConnectionFactory();
    IAGSServerConnection agsServerConnection = agsServerConnectionFactory.open
        (propertySet, 0);
    IAGSEnumServerObjectName enumServerObjectName =
        agsServerConnection.getServerObjectNames();
    enumServerObjectName.reset();
    // Iterate through the objects to locate the geodata service.
    IAGSServerObjectName serverObjectName = null;
    IGeoDataServer geoDataServer = null;
    while ((serverObjectName = enumServerObjectName.next()) != null){
        if (serverObjectName.getName().equals(serviceName)){
            IName name = (IName)serverObjectName;
            geoDataServer = (IGeoDataServer)name.open();
            break;
        }
    }
    return geoDataServer;
}
  • 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:
[Java]
// For example, machineName = "jerome"
// serviceName = "FileGDB_GDS"
static IGeoDataServer initGeoDataServerFromNetworkServer(String machineName, String
    serviceName)throws Exception{
    // Create a property set for connection properties.
    IPropertySet propertySet = new PropertySet();
    propertySet.setProperty("Machine", machineName);
    // Connect to the server and get an enumerator for its objects.
    IAGSServerConnectionFactory agsServerConnectionFactory = new
        AGSServerConnectionFactory();
    IAGSServerConnection agsServerConnection = agsServerConnectionFactory.open
        (propertySet, 0);
    IAGSEnumServerObjectName enumServerObjectName =
        agsServerConnection.getServerObjectNames();
    enumServerObjectName.reset();
    // Iterate through the objects to locate the geodata service.
    IAGSServerObjectName serverObjectName = null;
    IGeoDataServer geoDataServer = null;
    while ((serverObjectName = enumServerObjectName.next()) != null){
        if (serverObjectName.getName().equals(serviceName)){
            IName name = (IName)serverObjectName;
            geoDataServer = (IGeoDataServer)name.open();
            break;
        }
    }
    return geoDataServer;
}






Development licensing Deployment licensing
ArcView ArcView
ArcEditor ArcEditor
ArcInfo ArcInfo