In this topic
- About workspaces
- 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
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);
}
[VB.NET]
' For example, path = "C:\myData\myfGDB.gdb".
Public Shared Function FileGdbWorkspaceFromPath(ByVal Path As String) As IWorkspace
Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory")
Dim workspaceFactory As IWorkspaceFactory = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory)
Return workspaceFactory.OpenFromFile(Path, 0)
End Function
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);
}
[VB.NET]
' For example, path = "C:\myData\mypGDB.mdb".
Public Shared Function AccessWorkspaceFromPath(ByVal Path As String) As IWorkspace
Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory")
Dim workspaceFactory As IWorkspaceFactory = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory)
Return workspaceFactory.OpenFromFile(Path, 0)
End Function
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);
}
[VB.NET]
' For example, server = "Kona".
' Database = "SDE" or "" if Oracle.
' Instance = "5151".
' User = "vtest".
' Password = "go".
' Version = "SDE.DEFAULT".
Public Shared Function ConnectToTransactionalVersion(ByVal server As String, ByVal instance As String, _
ByVal user As String, ByVal password As String, ByVal database As String, ByVal Version As String) As IWorkspace
Dim propertySet As IPropertySet = 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)
Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory")
Dim workspaceFactory As IWorkspaceFactory = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory)
Return workspaceFactory.Open(PropertySet, 0)
End Function
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);
}
[VB.NET]
' For example, server = "Kona".
' database = "sde" or "" if Oracle.
' instance = "5151".
' user = "vtest".
' password = "go".
' historicalName = "Year End 2006".
Public Shared Function ConnectoToHistoricalVersion(ByVal server As String, ByVal instance As String, _
ByVal user As String, ByVal password As String, ByVal database As String, ByVal historicalName As String) As IWorkspace
Dim propertySet As IPropertySet = 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)
Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory")
Dim workspaceFactory As IWorkspaceFactory = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory)
Return workspaceFactory.Open(propertySet, 0)
End Function
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);
}
[VB.NET]
' For example, server = "Kona".
' database = "sde".
' instance = "5151".
' user = "vtest".
' password = "go".
' timestamp = "1/1/2006 12:00:01 AM".
Public Shared Function ConnectToHistoricalTimestamp(ByVal server As String, ByVal instance As String, _
ByVal user As String, ByVal password As String, ByVal database As String, ByVal timestamp As String) As IWorkspace
Dim propertySet As IPropertySet = 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.
Dim dateTime As DateTime = Convert.ToDateTime(timestamp)
propertySet.SetProperty("HISTORICAL_TIMESTAMP", dateTime)
Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory")
Dim workspaceFactory As IWorkspaceFactory = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory)
Return workspaceFactory.Open(propertySet, 0)
End Function
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);
}
[VB.NET]
' For example, connectionFile = "C:\myData\Connection to Kona.sde".
Public Shared Function ArcSdeWorkspaceFromFile(ByVal connectionFile As String) As IWorkspace
Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory")
Dim workspaceFactory As IWorkspaceFactory = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory)
Return workspaceFactory.OpenFromFile(connectionFile, 0)
End Function
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);
}
[VB.NET]
' For example, connectionString = "SERVER=Kona;DATABASE=sde;INSTANCE=5151;USER=Editor;PASSWORD=Editor;VERSION=sde.DEFAULT".
Public Shared Function ArcSdeWorkspaceFromString(ByVal connectionString As String) As IWorkspace
Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory")
Dim workspaceFactory2 As IWorkspaceFactory2 = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory2)
Return workspaceFactory2.OpenFromString(connectionString, 0)
End Function
Connecting to personal and workgroup ArcSDE geodatabases
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);
}
[VB.NET]
' 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 Shared Function WorkgroupArcSdeWorkspaceFromPropertySet(ByVal server As String, ByVal instance As String, _
ByVal authenticationMode As String, ByVal database As String, ByVal Version As String) As IWorkspace
Dim propertySet As IPropertySet = New PropertySetClass()
propertySet.SetProperty("SERVER", server)
propertySet.SetProperty("INSTANCE", instance)
propertySet.SetProperty("DATABASE", database)
propertySet.SetProperty("AUTHENTICATION_MODE", authenticationMode)
propertySet.SetProperty("VERSION", Version)
Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory")
Dim workspaceFactory As IWorkspaceFactory = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory)
Return workspaceFactory.Open(propertySet, 0)
End Function
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);
}
[VB.NET]
' For example, connectionFile = "C:\myData\Connection to tivo.sde".
Public Shared Function WorkgroupArcSdeWorkspaceFromFile(ByVal connectionFile As String) As IWorkspace
Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory")
Dim workspaceFactory As IWorkspaceFactory = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory)
Return workspaceFactory.OpenFromFile(connectionFile, 0)
End Function
Using the OpenFromString method to open a personal or workspace ArcSDE geodatabase only differs from opening an enterprise ArcSDE 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);
}
[VB.NET]
' For example, connectionString = "SERVER=tivo_sqlexpress;DATABASE=sewer;INSTANCE=sde:sqlserver:tivo\sqlexpress;AUTHENTICATION_MODE=OSA;VERSION=dbo.DEFAULT".
Public Function WorkgroupArcSdeWorkspaceFromString(ByVal connectionString As String) As IWorkspace
Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory")
Dim workspaceFactory2 As IWorkspaceFactory2 = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory2)
Return workspaceFactory2.OpenFromString(connectionString, 0)
End Function
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;
}
[VB.NET]
' For example, serverName = "tivo\sqlexpress".
' gdbName = "sewer".
' versionPropName = "VERSION".
' versionName = "dbo.DEFAULT".
Public Shared Function WorkgroupArcSdeWorkspaceFromDSM(ByVal serverName As String, ByVal gdbName As String, _
ByVal versionPropName As String, ByVal versionName As String) As IWorkspace
' Create a Data Server Manager object.
Dim dataServerManager As IDataServerManager = 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.
Dim dataServerManagerAdmin As IDataServerManagerAdmin = CType(dataServerManager, IDataServerManagerAdmin)
Dim workspaceName As IWorkspaceName = dataServerManagerAdmin.CreateWorkspaceName(gdbName, versionPropName, versionName)
' Cast from the workspace name to utilize the Open method.
Dim Name As IName = CType(workspaceName, IName)
Dim workspace As IWorkspace = CType(Name.Open(), IWorkspace)
Return workspace
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):
ESRI.ArcGIS.DataSourcesGDB ESRI.ArcGIS.System (ESRI.ArcGIS.esriSystem)ESRI.ArcGIS.Geodatabase
Development licensing | Deployment licensing |
---|---|
ArcView | ArcView |
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |
Engine Developer Kit | Engine Runtime |