Feb 15, 2012

How to connect to a ESRI Geodatabase and return workspace.

Initialize Product License with License Initializer

Connecting to GeoDB is the first step of querying the GeoDB. Inorder to work with the ArcObjects, the ArcGIS license has to be initialized. ESRI provides a License initializer project downloaded from the below link.

Download the Project and add it to your solution which uses arcObjects. Set the Project InitializeProductLicense as the startup and run the project. Debug and see what is the license status returned.

below are the different cases returned

IF the return value is isriLicenseCheckedOut, then license is intialized.     
Below is the method that get path of the geoDB say C:\\test\\Test.gdb and returns the workspace that can be queried for different scenarios.              
Namespace Used:

using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.DataSourcesGDB;
using ESRI.ArcGIS.Geometry;

public static IWorkspace FileGdbWorkspaceFromPropertySet(String path)
            //Initialize the application.
            esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;
            IAoInitialize m_AoInitialize = new AoInitializeClass();
            licenseStatus = m_AoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcView);
            Type factoryType = Type.GetTypeFromProgID(
            IWorkspaceFactory2 workspaceFactory = (IWorkspaceFactory2)Activator.CreateInstance
            return workspaceFactory.OpenFromFile(path, 0);

In the next post will see how to query parcels intersecting a envelope in the GeoDB.