DataSourcesOleDB


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

Additional library information: Contents, Object Model Diagram

The DataSourcesOleDB library contains the implementation of the GeoDatabase API for the Microsoft OLE DB data sources and text file data sources. These data sources include any OLE DB supported data provider and text file workspaces. It also provides a way to to use ADO to connect to an existing workspace.

 
 
The DataSourcesOleDB library is not extended by developers. It is only available on the Microsoft Windows operating system.

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

OleDBWorkspaceFactory and TextFileWorkspaceFactory

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 and feature classes. DataSourcesOleDB has workspace factories for connecting to OLE DB and text file 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.
 
This example demonstrates how to open a table from an OLE DB data source.

[C#]
// Create and populate a new property set
ESRI.ArcGIS.esriSystem.PropertySet propertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass();
propertySet.SetProperty ("CONNECTSTRING", "Provider=MSDAORA.1;Data source=mydatabase;User ID=oledb;Password=oledb");

// Create a new OleDB workspacefactory and open the OleDB workspace
IWorkspaceFactory workspaceFactory = new OLEDBWorkspaceFactoryClass();
ESRI.ArcGIS.Geodatabase.IWorkspace workspace = workspaceFactory.Open(propertySet, 0);

// Cast for IFeatureWorkspace
ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;

// Open a table
ESRI.ArcGIS.Geodatabase.ITable oledbTable = featureWorkspace.OpenTable("OLEDB.MY_TABLE");
This example demonstrates how to open a table from a TextFile data source.
[C#]
// Create a new TextFile workspacefactory and open the workspace
IWorkspaceFactory workspaceFactory = new TextFileWorkspaceFactoryClass();
ESRI.ArcGIS.Geodatabase.IWorkspace workspace = workspaceFactory.OpenFromFile("c:\\temp\\testing", 0);

// Cast for IFeatureWorkspace
ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;

// Open a table
ESRI.ArcGIS.Geodatabase.ITable oledbTable = featureWorkspace.OpenTable("farms.txt");

FdoAdoConnection

Use the FdoAdoConnection object whenever you want to create or connect to an ADO (ActiveX Data Objects) connection object from an existing workspace object.
 
The following example shows how to connect an ADO connection to an Access workspace.

[C#]
// Open an Access workspace
IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();
ESRI.ArcGIS.Geodatabase.IWorkspace workspace = workspaceFactory.OpenFromFile("c:\\temp\\us_states.mdb", 0);

// Connect the ADO connection to the access workspace
IFDOToADOConnection fdoToadoConnection = new FdoAdoConnectionClass();
ADODB.Connection adoConnection = new ADODB.Connection();
fdoToadoConnection.Connect(workspace, adoConnection);

//Issue an ADO query against an access data source
ADODB.Recordset adoRecordSet = new ADODB.Recordset();
adoRecordSet.Open("Select * from us_states", adoConnection, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockOptimistic,0);
The following example shows how to open an ADO connection and recordset from an Access workspace.
[C#]
// Open an Access workspace
IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();
ESRI.ArcGIS.Geodatabase.IWorkspace workspace = workspaceFactory.OpenFromFile("c:\\temp\\us_states.mdb", 0);

// Connect the ADO connection to the access workspace
IFDOToADOConnection fdoToadoConnection = new FdoAdoConnectionClass();
ADODB.Connection adoConnection = (ADODB.Connection)fdoToadoConnection.CreateADOConnection(workspace);

//Issue an ADO query against an access data source
ADODB.Recordset adoRecordSet = new ADODB.Recordset();
adoRecordSet.Open("Select * from us_states", adoConnection, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockOptimistic, 0);