The code below demonstrates how to connect to an SDE for Coverages workspace, open a feature class in that workspace, and add it to ArcMap.
How to use
- Paste the code into your VBA Application.
- Change the workspace connection string and the feature class name to open.
- Call AddSDECoverageLayer.
Public Sub AddSDECoverageLayer()
Dim pWorkFact As IWorkspaceFactory2
Dim pFWorkspace As IFeatureWorkspace
Dim pFClass As IFeatureClass
Dim pFLayer As IFeatureLayer
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pAV As IActiveView
'Open Feature Class
Set pWorkFact = New SdeWorkspaceFactory
Set pFWorkspace = pWorkFact.OpenFromString("server=luxor;instance=5156;user=avuser;password=avtest", 0)
Set pFClass = pFWorkspace.OpenFeatureClass("cities")
'Create new layer
Set pFLayer = New FeatureLayer
Set pFLayer.FeatureClass = pFClass
pFLayer.Name = pFClass.AliasName
'Add layer to map
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap
Set pAV = pMap
pMap.AddLayer pFLayer
pAV.Refresh
End Sub