DataSourcesGDB


Supported with:
Library dependencies: System, SystemUI, Geometry, Display, Server, Output, Geodatabase, GISClient, ArcWeb, DataSourcesFile

Additional library information: Contents, Object Model Diagram

The DataSourcesGDB library contains the implementation of the GeoDatabase API for the database data sources. These data sources include Microsoft Access, File Geodatabases, any RDBMS supported by ArcSDE and InMemory and Scratch workspaces.
 
The DataSourcesGDB library is not extended by developers.

The major objects within DataSourcesGDB are workspace factories and the Data Server Manager. A workspace factory object is a dispenser of workspaces and allows a client to connect to a workspace specified by a set of connection properties. A workspace represents a database or a data source that contains one or more datasets. Examples of datasets include tables, feature classes, and relationships. DataSourcesGDB has workspace factories for connecting to Access, File Geodatabase and ArcSDE data sources.
 
Workspace factories are cocreatable, singleton objects. (A singleton object can only be instantiated once in a process.) Each workspace factory maintains a pool of currently connected, active workspaces that are being referenced by the application. Connection properties are specified using a PropertySet object and can be saved to a connection file.
 
The AccessWorkspaceFactory, FileGDBWorkspaceFactory, ScratchWorkspaceFactory, and SdeWorkspaceFactory workspace factories are included in the DataSourcesGDB library.

 

The objects that implement this functionality are grouped into a number of library subsystems. These library subsystems are:

AccessWorkspaceFactory

An AccessWorkspaceFactory is used to connect to a Microsoft Access database.
 
The following example shows how to create and connect to an Access database.

[C#]
// Create an access workspace factory
ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory = new
  AccessWorkspaceFactoryClass();

// Create a new Access workspace\personal geodatabase
ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName = workspaceFactory.Create(
  "C:\\temp\\", "MyPGDB.mdb", null, 0);

// Cast for IName
ESRI.ArcGIS.esriSystem.IName name = (IName)workspaceName;

//Open a reference to the access workspace through the name object
ESRI.ArcGIS.Geodatabase.IWorkspace pGDB_Wor = (IWorkspace)name.Open();

//Open another Access Workspace
pGDB_Wor = workspaceFactory.OpenFromFile("C:\\temp\\us_states.mdb", 0);

FileGDBWorkspaceFactory

A FileGDBWorkspaceFactory is used to connect to a File geodatabase. Note that a file Geodatabase is denoted by the gdb extension as opposed to Access workspaces with have an mdb extension.
 
The following example shows how to create and then connect to a ile geodatabase.

[C#]
// Create an file geodatabase workspace factory
ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory = new
  FileGDBWorkspaceFactoryClass();

// Create a new file geodatabase
ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName = workspaceFactory.Create(
  "C:\\temp\\", "MyFGDB.gdb", null, 0);

// Cast for IName
ESRI.ArcGIS.esriSystem.IName name = (IName)workspaceName;

//Open a reference to the file geodatabase workspace through the name object
ESRI.ArcGIS.Geodatabase.IWorkspace fGDB_Wor = (IWorkspace)name.Open();

//Open another file geodatabase Workspace
fGDB_Wor = workspaceFactory.OpenFromFile("C:\\temp\\us_states.gdb", 0);

ScratchWorkspaceFactory

A ScratchWorkspaceFactory is used to connect to a temporary database stored in either Microsoft Access or within a file geodatabase. These workspaces are commonly used to hold the results of a selection set or to hold the results of an analysis operation. This workspace factory is fundamentally different than the AccessWorkspaceFactory and FileGDBWorkspaceFactory in a couple of ways. First, there are interfaces (IScratchWorkspaceFactory and IScratchWorkspaceFactory2) on it to create new temporary workspaces or connect to existing temporary workspaces. Second, when the last reference to the workspace is released, the workspace is automatically deleted from the disk.
 
A new type of scratch workspace factory was added at 9.2 which uses a file geodatabase instead of an Access database.  The new scratch workspace factory, FileScratchWorkspaceFactory does not replace the existing ScratchWorkspaceFactory but instead is meant to take advantage of file geodatabases in that it is cross platform and can be used across different operating systems.
 
The following example shows how to get the current scratch workspace to use as part of a selection.  This example uses the scratch workspace implementation which uses Access databases.

[C#]
// Create a new scratch workspace factory
ESRI.ArcGIS.Geodatabase.IScratchWorkspaceFactory workspaceFactory = new
  ScratchWorkspaceFactoryClass();
ESRI.ArcGIS.Geodatabase.IScratchWorkspaceFactory2 workspaceFactory2 =
  workspaceFactory as IScratchWorkspaceFactory2;

// Get the current scratch workspace
ESRI.ArcGIS.Geodatabase.IWorkspace scratchWorkspace =
  workspaceFactory2.CurrentScratchWorkspace;

//Select from an existing table, called parcelTable, using an existing query, called queryFilter
//putting the resulting selection set in the temporary workspace
ESRI.ArcGIS.Geodatabase.ISelectionSet selSet = parcelTable.Select(queryFilter,
  esriSelectionType.esriSelectionTypeHybrid,
  esriSelectionOption.esriSelectionOptionNormal, scratchWorkspace);
The following example shows how to get the current scratch workspace to use as part of a selection.  This example uses the file geodatabase scratch workspace implementation.

[C#]
// Create a new scratch workspace factory
ESRI.ArcGIS.Geodatabase.IScratchWorkspaceFactory workspaceFactory = new
  FileGDBScratchWorkspaceFactoryClass();
ESRI.ArcGIS.Geodatabase.IScratchWorkspaceFactory2 workspaceFactory2 =
  workspaceFactory as IScratchWorkspaceFactory2;
// Get the current scratch workspace
ESRI.ArcGIS.Geodatabase.IWorkspace scratchWorkspace =
  workspaceFactory2.CurrentScratchWorkspace;
//Select from an existing table, called parcelTable, using an existing query, called queryFilter
//putting the resulting selection set in the temporary workspace
ESRI.ArcGIS.Geodatabase.ISelectionSet selSet = parcelTable.Select(queryFilter,
  esriSelectionType.esriSelectionTypeHybrid,
  esriSelectionOption.esriSelectionOptionNormal, scratchWorkspace);

SdeWorkspaceFactory

A SdeWorkspaceFactory is used to connect to an ArcSDE database. There are a few interfaces on this workspace factory that are important to ArcSDE data sources. ISetDefaultConnectionInfo and ISetDefaultConnectionInfo2 are used to specify the username, password, and version of connections to SDE workspaces when those parameters are not specified by the connection properties. This is important if you want to save a connection file that does not persist this information. IRemoteDatabaseWorkspaceFactory is used to maintain connection files. These files, which store the connection properties used to connect to ArcSDE workspaces, commonly have the .sde extension.
[C#]
// Gets a reference to an existing workspace via a set of connection properties
public ESRI.ArcGIS.Geodatabase.IWorkspace arcSDEWorkspaceOpen(String server,
  String instance, String user, String password, String database, String
  version)
{
  try
  {
    // Create and populate the property set
    ESRI.ArcGIS.esriSystem.IPropertySet propertySet = new
      ESRI.ArcGIS.esriSystem.PropertySetClass();
    propertySet.SetProperty("SERVER", server);
    propertySet.SetProperty("INSTANCE", instance);
    propertySet.SetProperty("DATABASE", database);
    propertySet.SetProperty("USER", user);
    propertySet.SetProperty("PASSWORD", password);
    propertySet.SetProperty("VERSION", version);

    ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2 workspaceFactory;
    workspaceFactory = (ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2)new
      SdeWorkspaceFactoryClass();
    return workspaceFactory.Open(propertySet, 0);
  }
  catch (Exception e)
  {
    throw new Exception(String.Format("arcSDEWorkspaceOpen: {0}", e.Message), e)
      ;
  }
}

Data Server Manager

The DataServerManager is used to access and administer one or more Geodatabases stored on a data server.  You can also open a connection to each geodatabase in a DataServer through the use of the IWorkspaceName and IName interfaces.  The following example shows how to connect to a Geodatabase stored in a DataServer for Personal or Workgroup ArcSDE using the DataServerManager.
[C#]
// Create a Data Server Manager object
IDataServerManager dataserverManager = new DataServerManagerClass();

// Set the server name and connect to the server
dataserverManager.ServerName = "tivo\\sqlexpress";
dataserverManager.Connect();

// Open one of the geodatabases in the Database Server
IDataServerManagerAdmin dataservermanagerAdmin = (IDataServerManagerAdmin)
  dataserverManager;
ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName =
  dataservermanagerAdmin.CreateWorkspaceName("sewer", "VERSION", "dbo.Default");
ESRI.ArcGIS.esriSystem.IName name = (IName)workspaceName;
ESRI.ArcGIS.Geodatabase.IWorkspace GDB_wor = (IWorkspace)name.Open();

InMemoryWorkspaceFactory

An InMemoryWorkspaceFactory is used to connect to a temporary workspace which is stored in memory. These workspaces are commonly used to hold the results of an analysis operation or to hold objects in memory before persisting them to disk. When the last reference to the workspace is released, the workspace is destroyed and the memory released.
 
InMemory workspaces support tables and simple feature classes with geometries of point, multipoint, multipatch, polyline and polygon. Zs and Ms are supported.  Feature classes and tables contained within InMemory workspaces support the full geodatabase model in terms of being used in conjunction with cursors, selections, etc.
What follows is a description of what is not supported by InMemory workspaces.  This list may not be exhaustive as it reflects the most commonly used aspects of the Geodatabase data model.  InMemory workspaces do not support the following:

[C#]
// Create an InMemory workspace factory
IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();

// Create a new InMemory geodatabase
ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName = workspaceFactory.Create(
  "", "MyWorkspace", null, 0);

// Cast for IName
ESRI.ArcGIS.esriSystem.IName name = (IName)workspaceName;

//Open a reference to the access workspace through the name object
ESRI.ArcGIS.Geodatabase.IWorkspace inmemWor = (IWorkspace)name.Open();