Library Reference  

DataSourcesOleDB Library Overview


Supported with: ArcGIS Engine, ArcGIS Desktop, ArcGIS Server

Library dependencies: System, SystemUI, Geometry, Display, Server, Output, GeoDatabase, GISClient, DataSourcesFile, DataSourcesGDB


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 can be grouped into two categories:


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.

[Visual Basic 6.0]
'Create and populate a new property set
Dim pPropset As IPropertySet
Set pPropset = New PropertySet
pPropset.SetProperty "CONNECTSTRING", "Provider=MSDAORA.1;Data source=mydatabase;User ID=oledb;Password=oledb"

'Create a new OleDB workspacefactory and open the OleDB workspace
Dim pWorkspaceFact As IWorkspaceFactory
Dim pFeatWorkspace As IFeatureWorkspace
Set pWorkspaceFact = New esriDataSourcesOLEDB.OLEDBWorkspaceFactory
Set pFeatWorkspace = pWorkspaceFact.Open(pPropset, 0)

'Open a table object
Dim pTable As ITable
Set pTable = pFeatWorkspace.OpenTable("OLEDB.MY_TABLE")

This example demonstrates how to open a table from a TextFile data source.

[Visual Basic 6.0]
'Create a new TextFile WorkspaceFactory and open TextFile workspace
Dim pFact As IWorkspaceFactory
Dim pFeatws As IFeatureWorkspace
Set pFact = New esriDataSourcesOLEDB.TextFileWorkspaceFactory
Set pFeatws = pFact.OpenFromFile("d:\tables81\testing", 0)

'Open a table object
Dim pTable As ITable
Set pTable = pFeatws.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.

[Visual Basic 6.0]
Dim m_WrkSpcFact As IWorkspaceFactory
Dim m_accWS As IWorkspace
Dim m_fdoCon As IFDOToADOConnection
Dim m_adocon as adodb.connection
Dim adors as adodb.recordset

'Open an access workspace
Set m_WrkSpcFact = New esriDataSourcesGDB.AccessWorkspaceFactory
Set m_accWS = m_WrkSpcFact.OpenFromFile("d:\data\access\us_states.mdb", 0)

'Connect the ADO connection to the access workspace
Set m_fdoCon = New FdoAdoConnection
Set m_adocon = New adodb.connection
m_fdoCon.Connect m_accWS, m_adocon

'Issue an ADO query against an access data source
Set adors = new adodb.recordset
adors.Open "Select * from us_states", m_adoCon, adOpenForwardOnly, adLockOptimistic

The following example shows how to open an ADO connection and recordset from an Access workspace.

[Visual Basic 6.0]
Dim m_WrkSpcFact As IWorkspaceFactory
Dim m_accWS As IWorkspace
Dim m_fdoCon As IFDOToADOConnection
Dim m_adoCon As ADODB.connection
Dim m_adors As ADODB.Recordset

'Open an access workspace
Set m_WrkSpcFact = New esriDataSourcesGDB.AccessWorkspaceFactory
Set m_accWS = m_WrkSpcFact.OpenFromFile("d:\data\access\us_states.mdb", 0)

'Open a new ADO connection pointing at an access workspace
Set m_fdoCon = New FdoAdoConnection
Set m_adoCon = m_fdoCon.CreateADOConnection(m_accWS)

'Issue an ADO query against an access data source
Set m_adors = New ADODB.Recordset
m_adors.Open "select * from us_states", m_adoCon, adOpenForwardOnly, adLockOptimistic