声明:仅做自己学习整理用,内容拷贝自ArcEngine SDK开发文档

Creating geodatabases

Summary This topic explains how to create several types of geodatabases, including personal, file, personal and workgroup ArcSDE, and two types of scratch workspaces. It also describes how to create a connection file to an ArcSDE geodatabase.

In this topic

  • About workspaces
  • Creating a file geodatabase
  • Creating a personal geodatabase
  • Creating a connection file to an enterprise ArcSDE geodatabase
  • Creating a geodatabase in personal or workgroup ArcSDE
  • Creating a scratch workspace

About workspaces

A workspace is a container of spatial and nonspatial datasets, such as feature classes, raster datasets, and tables. Workspaces provide methods to instantiate existing datasets and to create datasets. The following are the three types of workspaces:
  • Shapefiles and ArcInfo workspaces are examples of file system workspaces.
  • Personal and file geodatabases are examples of local geodatabase workspaces.
  • An ArcSDE geodatabase stored in a relational database management system (RDBMS), such as Oracle, DB2, Structured Query Language (SQL) Server, or Informixis an example of a remote geodatabase workspace.
To create a workspace, first create an appropriate workspace factory. Each workspace type has its own workspace factory. A workspace factory is a dispenser of workspaces and allows a client to create a workspace specified by the directory, file name, and/or connection properties. A workspace factory is a co-creatable singleton object (see Interacting with singleton objects). A singleton object can only be instantiated once in a process. The workspace factory classes for geodatabase workspaces are found in the DataSourcesGDB library, while those for the non-geodatabase workspaces mentioned in this topic are found in the DataSourcesFile library.
The Create method can be used to create a file system workspace or local geodatabase, or to create a connection file to an ArcSDE geodatabase. The connectionProperties parameter specifies any additional connection properties needed for ArcSDE geodatabases, such as the server, instance, and so on.
When a connection file to an ArcSDE geodatabase is being created—if no connection properties are specified—a dialog box appears prompting the user for the required properties. The hWnd parameter gives the Create method a handle to a parent window. Typically, a value of 0 can be used.
The Create method returns an IWorkspaceName reference that can be used to open or return certain information about the workspace. The Create method cannot be used to create geodatabases in an enterprise, personal, or workgroup ArcSDE (see Creating a geodatabase in a personal or workgroup ArcSDE workspace in this topic).
Activator.CreateInstance vs. NewThe examples in this topic instantiate workspace factories using the Activator.CreateInstance method rather than the new keyword. This is because workspace factories are singleton Component Object Model (COM) classes. For more information, see Interacting with singleton objects. 

Creating a file geodatabase

The required workspace factory to create a file geodatabase is a FileGDBWorkspaceFactory. The following code example creates a file geodatabase in the specified directory with the supplied name. The connectionProperties parameter is null as it is not required for the creation of a personal geodatabase.

[C#]

public static IWorkspace CreateFileGdbWorkspace(String path)
{// Instantiate a file geodatabase workspace factory and create a file geodatabase.// The Create method returns a workspace name object.Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);IWorkspaceName workspaceName = workspaceFactory.Create(path, "Sample.gdb", null,0);// Cast the workspace name object to the IName interface and open the workspace.IName name = (IName)workspaceName;IWorkspace workspace = (IWorkspace)name.Open();return workspace;
}

Creating a personal geodatabase

The required workspace factory to create a personal geodatabase is an AccessWorkspaceFactory. The following code example creates a personal geodatabase in the specified directory with the supplied name. The connectionProperties parameter is null as it is not required for the creation of a personal geodatabase.

[C#]

public static IWorkspace CreateAccessWorkspace(String path)
{// Instantiate an Access workspace factory and create a personal geodatabase.// The Create method returns a workspace name object.Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory");IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);IWorkspaceName workspaceName = workspaceFactory.Create(path, "Sample.mdb", null,0);// Cast the workspace name object to the IName interface and open the workspace.IName name = (IName)workspaceName;IWorkspace workspace = (IWorkspace)name.Open();return workspace;
}

Creating a connection file to an enterprise ArcSDE geodatabase

When invoked on an ArcSDE workspace factory, the Create method does not create a geodatabase; instead, it creates an ArcSDE connection file.
The following are the two different procedures used to create an ArcSDE geodatabase:
  • One is used for creating ArcSDE personal and workgroup geodatabases.
  • The other is used to create ArcSDE enterprise geodatabases.
ArcSDE enterprise geodatabases are stored using separate database management system (DBMS) products. Therefore, before creating the ArcSDE geodatabase system tables and your data tables, set up the underlying DBMS. The specifics of this vary based on the type of DBMS being used.
The following code example shows how to use the Create method to make an ArcSDE connection file to an ArcSDE geodatabase:

[C#]

public static IWorkspaceName CreateConnectionFile(String path, String server, Stringinstance, String user, String password, String database, String version)
{IPropertySet propertySet = new 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);Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);return workspaceFactory.Create(path, "Sample.sde", propertySet, 0);
}

Creating a geodatabase in personal or workgroup ArcSDE

The DataServerManager is used to access and administer one or more geodatabases stored on a data server. A connection can also be opened to each geodatabase in a data server by using the IWorkspaceName and IName interfaces. The following code example shows how to create a geodatabase in a personal or workgroup ArcSDE using the DataServerManager.
Creating a geodatabase in a personal or workgroup ArcSDE creates databases on an SQL Server Express database instance. Only database server administrators can create ArcSDE personal or workgroup geodatabases.

[C#]

// dataServerName parameter should be in "<machine_name>\\<sql_instance>" format.
public static void CreatePersonalOrWorkgroupArcSdeWorkspace(String dataServerName)
{// Create a data server manager object.IDataServerManager dataServerManager = new DataServerManagerClass();// Set the server name and connect to the server.dataServerManager.ServerName = dataServerName;dataServerManager.Connect();// Cast to the admin interface, check permissions, and create the geodatabase.IDataServerManagerAdmin dataServerManagerAdmin = (IDataServerManagerAdmin)dataServerManager;if (dataServerManagerAdmin.IsConnectedUserAdministrator){dataServerManagerAdmin.CreateGeodatabase("LandUse", @"C:\Temp\LandUse.mdf",0, "", 0);// Create a Name object to open the workspace.IWorkspaceName workspaceName = dataServerManagerAdmin.CreateWorkspaceName("LandUse", "VERSION", "dbo.Default");IName name = (IName)workspaceName;IWorkspace workspace = (IWorkspace)name.Open();}
}

Creating a scratch workspace

The ScratchWorkspaceFactory and FileGDBScratchWorkspaceFactory classes are used to connect to a temporary file or personal geodatabase known as a scratch workspace. These workspaces are commonly used to store intermediate results in operations that require several steps. These factories are fundamentally different from the FileGDBWorkspaceFactory and AccessWorkspaceFactory classes for the following two reasons:
  • The factories implement interfaces specific to scratch workspaces (IScratchWorkspaceFactory and IScratchWorkspaceFactory2). The methods and properties of these interfaces are designed specifically for temporary geodatabases.
  • Scratch workspaces were designed to be created and used within a single session. If an application is started again at a later time, there is no reliable method for retrieving data that was previously stored in a scratch workspace.
The two types of scratch workspace factories are used in a similar manner, but scratch workspaces created as file geodatabases can take advantage of their cross-platform characteristics and can handle larger amounts of data.
Scratch workspace factories maintain a "default" scratch workspace. The first time the default scratch workspace is requested, a scratch workspace will be created and returned. Subsequent requests within the same session returns the same scratch workspace.
The following code example shows how to request the default scratch workspace:

[C#]

public static IWorkspace OpenScratchWorkspace()
{// Create a scratch workspace factory.Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.ScratchWorkspaceFactory");IScratchWorkspaceFactory scratchWorkspaceFactory = (IScratchWorkspaceFactory)Activator.CreateInstance(factoryType);// Get the default scratch workspace.IWorkspace scratchWorkspace = scratchWorkspaceFactory.DefaultScratchWorkspace;return scratchWorkspace;
}
The following code example shows how to get the default scratch workspace based on a file geodatabase:

[C#]

public static IWorkspace OpenFileGdbScratchWorkspace()
{// Create a file scratch workspace factory.Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBScratchWorkspaceFactory");IScratchWorkspaceFactory scratchWorkspaceFactory = (IScratchWorkspaceFactory)Activator.CreateInstance(factoryType);// Get the default scratch workspace.IWorkspace scratchWorkspace = scratchWorkspaceFactory.DefaultScratchWorkspace;return scratchWorkspace;
}

Connecting to a geodatabase

SummaryThis topic demonstrates how to connect to each type of geodatabase. It also shows how to connect to a transactional or historical version of an ArcSDE geodatabase.

In this topic

  • About workspaces

    • Methods for connecting to a workspace
  • Connecting to file geodatabases
  • Connecting to personal geodatabases
  • Connecting to enterprise ArcSDE geodatabases
    • Connecting to a transactional version
    • Connecting to a historical marker name
    • Connecting to a historical time stamp
  • Connecting to personal and workgroup ArcSDE geodatabases
    • Using the workspace factory
    • Using the DataServerManager

About workspaces

A workspace is a container of spatial and nonspatial datasets, such as feature classes, raster datasets, and tables. Workspaces provide methods to access existing datasets and to create datasets.
The following are the three types of workspaces (represented by values in the esriWorkspaceType enumeration):
  • Shapefile workspaces and ArcInfo workspaces are examples of file-based workspaces (esriFileSystemWorkspace).
  • Personal and file geodatabases are examples of local database workspaces (esriLocalDatabaseWorkspace).
  • An ArcSDE geodatabase stored in a relational database management system (RDBMS) such as Oracle, DB2, Structured Query Language (SQL) Server, Informix or PostgreSQL is a remote database workspace (esriRemoteDatabaseWorkspace).
There are several methods that can be used to open a geodatabase workspace, each with its own purpose. This topic reviews these methods for different types of workspaces and discusses when one can offer advantages over another.
To open a workspace, an appropriate workspace factory must be created. Each workspace type has its own workspace factory.
A workspace factory is a dispenser of workspaces and allows a client to connect to a workspace specified by a set of connection properties. A workspace factory is a co-creatable singleton object (see Interacting with singleton objects). A singleton object can only be instantiated once in a process. Workspace factory classes for geodatabases are located in the DataSourcesGDB library.

Methods for connecting to a workspace

The following are the three different methods to open a workspace from an appropriate workspace factory:
  • IWorkspaceFactory.Open—The Open method takes as input a set of connection properties that specify the workspace to establish a connection with.
  • IWorkspaceFactory.OpenFromFile—The OpenFromFile method takes the path name of a file or directory that represents a file-based workspace, a local geodatabase workspace, or an ArcSDE connection file and returns the appropriate workspace.
  • IWorkspaceFactory2.OpenFromString—The OpenFromString method on the IWorkspaceFactory2 interface was added to allow the opening of a workspace using a connection string that describes the connection properties for the workspace. The connection string is a collection of name value pairs separated by semicolons (;).
Each workspace factory maintains a pool of currently connected, active workspaces that are referenced by the application. When any of the previously listed Open* methods are called, the workspace factory verifies if a workspace has previously been opened with a matching set of properties. If so, a reference to the existing instance is returned.
In the case of ArcSDE workspaces, when an application connects to a workspace but omits some connection properties (such as user name, password, or version), the workspace factory checks a set of "core" properties—SERVER, INSTANCE, and AUTHENTICATION_MODE—to verify they match any open workspaces. If so, the workspace factory returns a reference to the matching workspace.

Connecting to file geodatabases

The required workspace factory to connect to a file geodatabase is the FileGDBWorkspaceFactory class. Typically, the OpenFromFile method is used to connect to a file geodatabase. The following code example shows how to call this method:

[C#]

// For example, path = @"C:\myData\myfGDB.gdb".
public static IWorkspace FileGdbWorkspaceFromPath(String path){ 
   Type factoryType = Type.GetTypeFromProgID(
        "esriDataSourcesGDB.FileGDBWorkspaceFactory");
    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance
        (factoryType);
    return workspaceFactory.OpenFromFile(path, 0);}

Connecting to personal geodatabases

The required workspace factory to connect to a personal geodatabase is the AccessWorkspaceFactory class. Typically, the OpenFromFile method is used to connect to a file geodatabase. The following code example shows how to call this method:

[C#]

// For example, path = @"C:\myData\mypGDB.mdb".
public static IWorkspace AccessWorkspaceFromPath(String path){
    Type factoryType = Type.GetTypeFromProgID(
        "esriDataSourcesGDB.AccessWorkspaceFactory");
    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance
        (factoryType);
    return workspaceFactory.OpenFromFile(path, 0);}

Connecting to enterprise ArcSDE geodatabases

The workspace factory to use to connect to an ArcSDE geodatabase is SdeWorkspaceFactory. The connection properties specify the server and instance to connect to and can be saved in a connection file (.sde) on the file system.
In the case of remote database workspaces accessed via ArcSDE, the properties can include the following connection properties of the database being connected to:
  • SERVER—The SDE server being connected to.
  • INSTANCE—The instance being connected to.
  • DATABASE—The database being connected to. The DATABASE property is optional and is required for ArcSDE instances that manage multiple databases (for example, SQL Server).
  • USER—The connected user.
  • PASSWORD—The connected user's password.
  • AUTHENTICATION_MODE—The credential authentication mode of the connection. Acceptable values are the operating system authentication (OSA) and database management system (DBMS). The default is DBMS. If the AUTHENTICATION_MODE is OSA, the USER and PASSWORD properties are not required. OSA uses the operating system credentials to establish a connection with the database.
  • VERSION—The transactional version to connect to. The acceptable value is a string that represents a transaction version name.
  • HISTORICAL_NAME—The historical version to connect to. The acceptable value is a string that represents a historical marker name.
  • HISTORICAL_TIMESTAMP—The moment in history to establish a historical version connection. The acceptable value is a date object containing a date time that represents a moment time stamp. The formatting of the date is DBMS specific (for example, SQLServer = "1/1/2006 12:00:01 AM").
Use one of the following three version properties—VERSION, HISTORICAL_NAME, or HISTORICAL_TIMESTAMP—since the workspace connection can only represent one version.
If any of the Open methods for a workspace are called with insufficient properties, a connection dialog box appears requesting the required properties. This can be used with ArcSDE workspaces to allow the user to connect with specific credentials (for example, enter a specific user name or password).

Connecting to a transactional version

In the following code example, a property set is populated from supplied strings to make a connection to an ArcSDE geodatabase workspace with a transactional version. The property set is then used by the Open method to return a workspace. This approach involves the most code; however, it can be customized into a general function for connecting to ArcSDE databases based on supplied parameters from the user.

[C#]

// For example, server = "Kona".// Database = "SDE" or "" if Oracle.// Instance = "5151".// User = "vtest".// Password = "go".// Version = "SDE.DEFAULT".
public static IWorkspace ConnectToTransactionalVersion(String server, String  instance, String user, String password, String database, String version){
    IPropertySet propertySet = new 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);
    Type factoryType = Type.GetTypeFromProgID(        "esriDataSourcesGDB.SdeWorkspaceFactory");
    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance        (factoryType);
    return workspaceFactory.Open(propertySet, 0);}

Connecting to a historical marker name

If archiving is enabled on data in an ArcSDE geodatabase, a historical version can be specified when connecting to the geodatabase. It is possible to create a named marker at some point. These markers are created with IHistoricalWorkspace and can be used to make a connection to this specific time.
To connect to a historical marker, augment the property set and replace the VERSION property with a HISTORICAL_NAME property. In the following code example, the name of the historical marker is Year End 2006:

[C#]

// For example, server = "Kona".// database = "sde" or "" if Oracle.// instance = "5151".// user = "vtest".// password = "go".// historicalName = "Year End 2006".
public static IWorkspace ConnectoToHistoricalVersion(String server, String instance,
    String user, String password, String database, String historicalName){
    IPropertySet propertySet = new PropertySetClass();
    propertySet.SetProperty("SERVER", server);
    propertySet.SetProperty("INSTANCE", instance);
    propertySet.SetProperty("DATABASE", database);
    propertySet.SetProperty("USER", user);
    propertySet.SetProperty("PASSWORD", password);
    propertySet.SetProperty("HISTORICAL_NAME", historicalName);
    Type factoryType = Type.GetTypeFromProgID( 
       "esriDataSourcesGDB.SdeWorkspaceFactory");
    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance 
       (factoryType);
    return workspaceFactory.Open(propertySet, 0);}

Connecting to a historical time stamp

It is also possible to connect at any time with the historical time stamp property. The following code example replaces the Historical_Name property with Historical_Timestamp to connect to an ArcSDE workspace on SQL Server. Convert a string representing a date to a date object when using it throughout the archiving application programming interface (API). This allows any date conversion errors to be handled before they are used to connect to a workspace.

[C#]

// For example, server = "Kona".// database = "sde".// instance = "5151".// user = "vtest".// password = "go".// timestamp = "1/1/2006 12:00:01 AM".
public static IWorkspace ConnectToHistoricalTimestamp(String server, String instance,
    String user, String password, String database, String timestamp){
    IPropertySet propertySet = new PropertySetClass();
    propertySet.SetProperty("SERVER", server);
    propertySet.SetProperty("INSTANCE", instance);
    propertySet.SetProperty("DATABASE", database); 
   propertySet.SetProperty("USER", user); 
   propertySet.SetProperty("PASSWORD", password);   // Convert a string representing a date to a date object when using it   // throughout the archiving API.
    DateTime dateTime = Convert.ToDateTime(timestamp); 
   propertySet.SetProperty("HISTORICAL_TIMESTAMP", dateTime);
    Type factoryType = Type.GetTypeFromProgID(
        "esriDataSourcesGDB.SdeWorkspaceFactory"); 
   IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance  
      (factoryType); 
   return workspaceFactory.Open(propertySet, 0);}
If an ArcSDE connection file created in ArcCatalog (or created programmatically with IWorkspaceFactory.Create) is used to organize and distribute the connection information for an ArcSDE geodatabase, the OpenFromFile method can be used to connect to the workspace.
In the following code example, the path to the .sde connection file stored on disk is used to create the connection with the OpenFromFile method:

[C#]

// For example, connectionFile = @"C:\myData\Connection to Kona.sde".
public static IWorkspace ArcSdeWorkspaceFromFile(String connectionFile){ 
   Type factoryType = Type.GetTypeFromProgID(
        "esriDataSourcesGDB.SdeWorkspaceFactory");
    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance 
       (factoryType);
    return workspaceFactory.OpenFromFile(connectionFile, 0);}
The OpenFromString method is most commonly used for convenience. An example of this is when a specific application accesses an ArcSDE geodatabase with well known connection properties. In this case, creating a string of the name-value pairs might be easier than creating a property set for the same parameters.
In the following code example, connection is made to the same ArcSDE instance as in the Open method example, except as a different user:

[C#]

// For example, connectionString = "SERVER=Kona;DATABASE=sde;INSTANCE=5151;USER=Editor;PASSWORD=Editor;VERSION=sde.DEFAULT".
public static IWorkspace ArcSdeWorkspaceFromString(String connectionString){
    Type factoryType = Type.GetTypeFromProgID(
        "esriDataSourcesGDB.SdeWorkspaceFactory");
    IWorkspaceFactory2 workspaceFactory2 = (IWorkspaceFactory2)
        Activator.CreateInstance(factoryType);
    return workspaceFactory2.OpenFromString(connectionString, 0);}
Personal and workgroup ArcSDE geodatabases are remote database workspaces and use the SdeWorkspaceFactory to make a connection to the workspace.

Using the workspace factory

Personal and workgroup ArcSDE geodatabases can be connected to using the same code. The code for both is also very similar to that of an enterprise ArcSDE geodatabase. Personal and workgroup ArcSDE geodatabases only support connections using direct connect and do not support the three-tier connections that an enterprise ArcSDE does.
Additionally, connections can only be made using OSA, where the user's operating system credentials are used for the user name and password. The geodatabases in a personal and workgroup ArcSDE are always owned by the database owner (dbo) user; the version names are prefixed by dbo.
The following code example contains minor differences from the code used to connect to an enterprise geodatabase. The direct connection is set up in the instance property. In this code example, the AUTHENTICATION_MODE property is also introduced. This property defaults to DBMS, which means that the DBMS will be used to authenticate the user's credentials. The authentication mode has been set to OSA instead of passing in the user name and password.

[C#]

// For example, for direct connect with OSA authentication.// Server = "tivo_sqlexpress".// Instance = "sde:sqlserver:tivo\\sqlexpress".// Database = "sewer".// Authentication_mode = "OSA".// Version = "dbo.DEFAULT".
public static IWorkspace WorkgroupArcSdeWorkspaceFromPropertySet(String server,
    String instance, String authenticationMode, String database, String version){
    IPropertySet propertySet = new PropertySetClass();
    propertySet.SetProperty("SERVER", server);
    propertySet.SetProperty("INSTANCE", instance);
    propertySet.SetProperty("DATABASE", database);
    propertySet.SetProperty("AUTHENTICATION_MODE", authenticationMode);
    propertySet.SetProperty("VERSION", version);
    Type factoryType = Type.GetTypeFromProgID(
        "esriDataSourcesGDB.SdeWorkspaceFactory");
    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance 
       (factoryType);
    return workspaceFactory.Open(propertySet, 0);}
The OpenFromFile method can also be used to connect to a personal or workgroup ArcSDE geodatabase. These files can be created manually in ArcCatalog or by using the Save Connection command after right-clicking a database server. This will create a .sde connection file in the Database Connections folder.
The connection files are then used in the OpenFromFile method as shown in the following code example:

[C#]

// For example, connectionFile = @"C:\myData\Connection to tivo.sde".
public static IWorkspace WorkgroupArcSdeWorkspaceFromFile(String connectionFile){
    Type factoryType = Type.GetTypeFromProgID(
        "esriDataSourcesGDB.SdeWorkspaceFactory");
    IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance
        (factoryType);
    return workspaceFactory.OpenFromFile(connectionFile, 0);}
geodatabase because of the string that is passed in. Ensure that OSA is set and that direct connect is used for the instance property value pair. See the following code example:

[C#]

// For example, connectionString = "SERVER=tivo_sqlexpress;DATABASE=sewer;INSTANCE=sde:sqlserver:tivo\\sqlexpress;AUTHENTICATION_MODE=OSA;VERSION=dbo.DEFAULT".
public IWorkspace WorkgroupArcSdeWorkspaceFromString(String connectionString){
    Type factoryType = Type.GetTypeFromProgID(
        "esriDataSourcesGDB.SdeWorkspaceFactory");
    IWorkspaceFactory2 workspaceFactory2 = (IWorkspaceFactory2)
        Activator.CreateInstance(factoryType);
    return workspaceFactory2.OpenFromString(connectionString, 0);}

Using the DataServerManager

The DataServerManager class is used to access and administer one or more geodatabases stored on a data server. A connection can be opened to each geodatabase in a data server through name objects returned by the CreateWorkspaceName method. Unlike an enterprise ArcSDE geodatabase, opening a connection to a geodatabase stored in a personal or workgroup ArcSDE does not require a set of properties. Instead, the geodatabase name, type of version, and version specifier are used.
The following are the three types of versions that can be used to connect to the geodatabase:
  • VERSION—Transactional version to connect to. The acceptable value is a string that represents a transaction version name.
  • HISTORICAL_NAME—Historical version to connect to. The acceptable value is a string that represents a historical marker name.
  • HISTORICAL_TIMESTAMP—Moment in history to establish a historical version connection. The acceptable value is a date object containing a date time that represents a moment time stamp.
The version specifier must correspond to the type of version (for example, if VERSION is specified, the version name must be listed as the version specifier). Also, since  the workspace connection can only represent one version, use only one of the three version properties (VERSION, HISTORICAL_NAME, or HISTORICAL_TIMESTAMP).
The following code example shows how to connect to a transactional version of a geodatabase stored in a DataServer for a personal or workgroup ArcSDE using the DataServerManager:

[C#]

// For example, serverName = "tivo\\sqlexpress".// gdbName = "sewer".// versionPropName = "VERSION".// versionName = "dbo.DEFAULT".
public static IWorkspace WorkgroupArcSdeWorkspaceFromDSM(String serverName, String    gdbName, String versionPropName, String versionName){ 
   // Create a Data Server Manager object.
    IDataServerManager dataServerManager = new DataServerManagerClass(); 
   // Set the server name and connect to the server.
    dataServerManager.ServerName = serverName;
    dataServerManager.Connect();    // Open one of the geodatabases in the database server.
    IDataServerManagerAdmin dataServerManagerAdmin = (IDataServerManagerAdmin)
        dataServerManager;
    IWorkspaceName workspaceName = dataServerManagerAdmin.CreateWorkspaceName 
       (gdbName, versionPropName, versionName);    // Cast from the workspace name to utilize the Open method. 
   IName name = (IName)workspaceName;
    IWorkspace workspace = (IWorkspace)name.Open();
    return workspace;}

GP学习(六)—Creating geodatabase and connecting geodatabase相关推荐

  1. GP学习(七)—Accessing raster workspaces

    声明:仅做自己学习整理用,内容拷贝自ArcEngine SDK开发文档 Accessing raster workspaces Summary Rasters can reside in a fold ...

  2. Apollo代码学习(六)—模型预测控制(MPC)_follow轻尘的博客-CSDN博客_mpc代码

    Apollo代码学习(六)-模型预测控制(MPC)_follow轻尘的博客-CSDN博客_mpc代码

  3. 艾伟:C#多线程学习(六) 互斥对象

    本系列文章导航 C#多线程学习(一) 多线程的相关概念 C#多线程学习(二) 如何操纵一个线程 C#多线程学习(三) 生产者和消费者 C#多线程学习(四) 多线程的自动管理(线程池) C#多线程学习( ...

  4. C#多线程学习(六) 互斥对象

    C#多线程学习(六) 互斥对象 原文链接:http://kb.cnblogs.com/page/42533/ 本系列文章导航 C#多线程学习(一) 多线程的相关概念 C#多线程学习(二) 如何操纵一个 ...

  5. OpenCV与图像处理学习六——图像形态学操作:腐蚀、膨胀、开、闭运算、形态学梯度、顶帽和黑帽

    OpenCV与图像处理学习六--图像形态学操作:腐蚀.膨胀.开.闭运算.形态学梯度.顶帽和黑帽 四.图像形态学操作 4.1 腐蚀和膨胀 4.1.1 图像腐蚀 4.1.2 图像膨胀 4.2 开运算与闭运 ...

  6. PyTorch框架学习六——图像预处理transforms(二)

    PyTorch框架学习六--图像预处理transforms(二) (续)二.transforms的具体方法 4.图像变换 (1)尺寸变换:transforms.Resize() (2)标准化:tran ...

  7. JMS学习六(ActiveMQ消息传送模型)

    JMS学习六(ActiveMQ消息传送模型) ActiveMQ 支持两种截然不同的消息传送模型:PTP(即点对点模型)和Pub/Sub(即发布 /订阅模型),分别称作:PTP Domain 和Pub/ ...

  8. Docker学习六:综合实践

    前言 本次学习来自于datawhale组队学习: 教程地址为: https://github.com/datawhalechina/team-learning-program/tree/master/ ...

  9. (转)MyBatis框架的学习(六)——MyBatis整合Spring

    http://blog.csdn.net/yerenyuan_pku/article/details/71904315 本文将手把手教你如何使用MyBatis整合Spring,这儿,我本人使用的MyB ...

最新文章

  1. 简明python教程 --C++程序员的视角(九):函数式编程、特殊类方法、测试及其他...
  2. 浅谈AJAX并实现使用pagehelper-5.1.10.jar分页插件实现异步从数据库中获取数据分页显示
  3. c/c++操作mysql数据库使用utf8总结
  4. wps图表xy轴颠倒_用EXCEL来搞艺术之图表类型变换
  5. memchache的数据类型_memcache详解
  6. jpanel把原本内容覆盖掉_暖冬遇上倒春寒,花被大雪覆盖,小心一夜回到解放前...
  7. c语言如何在手机上运行程序,各位前辈这两个程序怎么在手机上运行
  8. Gson反序列化详解
  9. 数据展现DataList控件(26)
  10. 通过波特率计算数据传输时间
  11. matlab单枝节匹配器,第八讲微带匹配电路单枝节匹配电路.ppt
  12. XUI 熟练使用之(一) ----------- 将 XUI 引入项目
  13. 从零开始自制实现WebServer(十九)---- 正式系统的学习一下Git 捣鼓捣鼓github以及一些其他的小组件
  14. lego_loam 代码阅读与总结
  15. get请求图片出现403 防盗链解决方式 no-referrer
  16. app推广有哪些方式?
  17. 关于16路及以上的X86服务器架构
  18. HDMI视频画面分割器的优势主要有哪些?
  19. pyinstaller打包-py获取依赖文件的绝对路径方法
  20. this kernel requires an x86-64 CPU, but only detected an i686 CPU. unable to boot - please ues a ke

热门文章

  1. bzoj1015 [JSOI2008]星球大战 并查集
  2. 2017.8.16 喵星球上的点名 思考记录
  3. node ajax validator,node/express 4:在ajax post上使用express-validator显示错误
  4. python turtle工具箱_python 库之 turtle(图形绘制) 开启新的快乐源泉
  5. 【英语学习】【Level 08】U01 Let's Read L1 All the world's a stage
  6. C#实现图(Graph)
  7. python Django之Web框架本质 (2)
  8. 4G通信技术LTE介绍
  9. php引用其他接口,PHP 接口与接口的引用
  10. Java返回int型的空值_使用MyBatis查询int类型字段,返回NULL值时报异常的解决方法...