How to connect to a geodatabase


Summary
This topic explains how to connect to file and ArcSDE geodatabases, and includes code examples for common connection scenarios.

In this topic


To use the code in this topic, add a reference to ESRI.ArcGISExplorer.dll. Also add the following namespace reference via using (C#) or Imports (VB .NET) statements:
  • ESRI.ArcGISExplorer.Data

Opening a file geodatabase

To open a file geodatabase, create an instance of the geodatabase class and specify the file path in the class constructor. See the following code example:
You cannot open personal geodatabases using ArcGIS Explorer. 
[C#]
Geodatabase fileGdb = new Geodatabase(@"C:\Data\Montgomery.gdb");
[VB.NET]
Dim fileGdb As Geodatabase = New Geodatabase("C:\Data\Montgomery.gdb")

Opening an ArcSDE geodatabase

Traditional and direct connections to an ArcSDE geodatabase are supported. A traditional connection relies on components on the remote server to open a connection to a geodatabase. Direct connections use components installed on the local client machine to communicate directly with the database management system (DBMS). Direct connections are only possible if the Data Access Expansion Pack has been installed. Your choice of connection mechanism is also determined by the type of ArcSDE geodatabase that you are connecting to as shown in the following table:
ArcSDE license level
Supports traditional connections
Supports direct connections
Personal (SQL Server Express)
No
Yes
Workgroup (SQL Server Express)
No
Yes
Enterprise (any supported DBMS)
Yes
Yes
Both connection mechanisms require that appropriate parameters are specified; although, there are several possible parameter combinations depending on the type of connection, type of DBMS, type of authentication, and type of version. The following table shows a complete list of all the connection parameters:
Parameter
Required
Description
Server
Traditional connect—yes
Direct connect—optional
The name or IP address of the machine running ArcSDE.
Service
Yes
For traditional connections, this is the name or port number of the ArcSDE instance. For direct connections, this will be all the information required to connect to the DBMS.
User
Yes, unless authentication mode is operating system (OS)
ArcSDE user name.
Password
Yes, unless authentication mode is OS
Password for the specified user.
Database
Optional, DBMS dependent
ArcSDE database to connect to.
Authentication mode
Optional
Specifies whether to connect using the logged in user's credentials for OS authentication or whether to use the user and password parameters for DBMS authentication. DBMS is the default.
Version type
Optional
Specifies the type of transactional version to connect to, which can be one the following: version, historical name, or historical time stamp. Version is the default type.
Version
Optional
Specifies which ArcSDE version to connect to. SDE.DEFAULT is the default version.
Historical name
Optional
Specifies the historical version to connect to.
Historical time stamp
Optional
Specifies the moment in history used to establish a historical version connection.
 
You can only choose one version type; therefore, connect to a version, historical name, or historical time stamp.

Using an ArcSDE connection file

ArcGIS Desktop users are usually familiar with geodatabase connections in ArcGIS Desktop, which can be saved as ArcSDE (.sde) connection files. To open a geodatabase using a connection file, create an instance of the geodatabase class and specify the file path in the class constructor. See the following code example:
[C#]
Geodatabase sdeGdb = new Geodatabase(@"C:\Data\Enterprise.sde");
[VB.NET]
Dim sdeGdb As Geodatabase = New Geodatabase("C:\Data\Enterprise.sde")

Traditional connections

To make a traditional connection to an ArcSDE geodatabase, create an instance of the ArcSDEConnectionProperties class, supply the appropriate connection parameters, and pass this object into the constructor of the geodatabase class. The following shows three examples of common connection scenarios:
The overloaded constructors on the ArcSDEConnectionProperties class are provided to help you choose the best combination of parameters for the type of geodatabase being opened.
  • Scenario 1—Connect to the default version of an Oracle ArcSDE geodatabase. See the following code example:
[C#]
//For example: server="leven",service="5151",user="scotuser",pwd="scotuser."
public Geodatabase OpenArcSDEGeodatabase(string server, string service, string
    user, string pwd)
{
    ArcSDEConnectionProperties sdeParams = new ArcSDEConnectionProperties
        (server, service, user, pwd);
    Geodatabase sdeGdb = new Geodatabase(sdeParams);
    return sdeGdb;
}
[VB.NET]
'For example: server="leven",service="5151",user="scotuser",pwd="scotuser."

Public Function OpenArcSDEGeodatabase(ByVal server As String, ByVal serviceAs String, ByVal user As String, ByVal pwd As String) As Geodatabase
    Dim sdeParams As ArcSDEConnectionProperties = New ArcSDEConnectionProperties(server, service, user, pwd)
    Dim sdeGdb As Geodatabase = New Geodatabase(sdeParams)
    Return sdeGdb
End Function
  • Scenario 2—Connect to the ApprovedParcels version of a Structured Query Language (SQL) server ArcSDE geodatabase (called LandBase) using OS authentication.

    In this scenario, the user and password connection parameter is not necessary because a connection is made using the Windows user name and password credentials of the currently logged on user. See the following code example:
[C#]
//For example: server="leven",service="esri_sde","LandBase","ApprovedParcels."
public Geodatabase OpenSQLServerArcSDEGeodatabase(string server, string service,
    string database, string version)
{
    ArcSDEConnectionProperties sdeParams = new ArcSDEConnectionProperties();
    sdeParams.Server = server;
    sdeParams.Service = service;
    sdeParams.Database = database;
    sdeParams.AuthenticationMode = AuthenticationMode.OS;
    sdeParams.VersionType = VersionType.Version;
    sdeParams.Version = version;
    Geodatabase sdeGdb = new Geodatabase(sdeParams);
    return sdeGdb;
}
[VB.NET]
'For example: server="leven",service="esri_sde","LandBase","ApprovedParcels."

Public Function OpenSQLServerArcSDEGeodatabase(ByVal server As String, ByVal service As String, ByVal database As String, ByVal Version As String) As Geodatabase
    Dim sdeParams As ArcSDEConnectionProperties = New ArcSDEConnectionProperties()
    sdeParams.Server = server
    sdeParams.Service = service
    sdeParams.Database = database
    sdeParams.AuthenticationMode = AuthenticationMode.OS
    sdeParams.VersionType = VersionType.Version
    sdeParams.Version = Version
    Dim sdeGdb As Geodatabase = New Geodatabase(sdeParams)
    Return sdeGdb
End Function
  • Scenario 3—Connect to the YearEnd2008 historical version of an Oracle ArcSDE geodatabase. See the following code example:
[C#]
//For example: server="leven",service="5151",user="scotuser",pwd="scotuser",VersionType.HistoricalName,"YearEnd2008."
public Geodatabase OpenHistoricalOracleArcSdeGeodatabase(string server, string
    service, string user, string pwd, VersionType type, string historicalName)
{
    ArcSDEConnectionProperties sdeParams = new ArcSDEConnectionProperties
        (server, service, user, pwd);
    sdeParams.VersionType = type;
    sdeParams.HistoricalName = historicalName;
    Geodatabase sdeGdb = new Geodatabase(sdeParams);
    return sdeGdb;
}
[VB.NET]
'For example: server="leven",service="5151",user="scotuser",pwd="scotuser",VersionType.HistoricalName,"YearEnd2008."

Public Function OpenHistoricalOracleArcSdeGeodatabase(ByVal server As String, ByVal service As String, ByVal user As String _
                                                      , ByVal pwd As String, ByVal Type As VersionType, ByVal historicalName As String) As Geodatabase
    Dim sdeParams As ArcSDEConnectionProperties = New ArcSDEConnectionProperties(server, service, user, pwd)
    sdeParams.VersionType = Type
    sdeParams.HistoricalName = historicalName
    Dim sdeGdb As Geodatabase = New Geodatabase(sdeParams)
    Return sdeGdb
End Function

Direct connections

A direct connection to an ArcSDE geodatabase can only be made if the client machine has been set up appropriately by doing the following:
For more information on configuring a client machine to be able to use direct connect, see the following ArcGIS Desktop topics:
To make a direct connection to an ArcSDE geodatabase, create an instance of the ArcSDEConnectionProperties class, supply the appropriate connection parameters, and pass this object into the constructor of the geodatabase class. Unlike a traditional connection, the Server property is not used and is always ignored even if it has been set. The Service property must contain the DBMS specific connection information. For more information, see Direct connections from ArcSDE commands to a geodatabase in SQL Server. The following scenario uses direct connect:
  • Scenario 4—Connect to the default version of an SQL Server Express, personal ArcSDE geodatabase (called TechPreview) using direct connect.

    In this scenario, only the service and database properties of the ArcSDEConnectionProperties instance need to be specified. The AuthenticationMode property defaults to use OS authentication and the Version property is set to DBO.Default. See the following code example:
[C#]
//For example: service=@"sde:sqlserver:torridon\sqlexpress", database="TechPreview");
public Geodatabase OpenPersonalArcSDEGeodatabaseDirectConnect(string service,
    string database)
{
    ArcSDEConnectionProperties sdeParams = new ArcSDEConnectionProperties
        (service, database);
    Geodatabase sdeGdb = new Geodatabase(sdeParams);
    return sdeGdb;
}
[VB.NET]
'For example: service="sde:sqlserver:torridon\sqlexpress", database="TechPreview");

Public Function OpenPersonalArcSDEGeodatabaseDirectConnect(ByVal service As String, ByVal database As String) As Geodatabase
    Dim sdeParams As ArcSDEConnectionProperties = New ArcSDEConnectionProperties(service, database)
    Dim sdeGdb As Geodatabase = New Geodatabase(sdeParams)
    Return sdeGdb
End Function
Use OS authentication when connecting to an SQL Server Express ArcSDE geodatabase.


See Also:

Geodatabase connections in ArcGIS Desktop
A quick tour of connections to ArcSDE geodatabases
What is a direct connection to a geodatabase in SQL Server?
Setting up a direct connection to SQL Server
Direct connections from ArcSDE commands to a geodatabase in SQL Server