Sunday, June 1, 2008

SDEWorkspaceFactory Example with Description

If you want to make a connection with any geodatabase or you want to establish sde connection then follow this code. It will help you a lot
This example opens a Geodatabase featureclass using a property set.

Dim pPropset As IPropertySet
Set pPropset = New PropertySet
Dim pFact As IWorkspaceFactory
Dim pWorkspace As IWorkspace
With pPropset
.SetProperty "Server", "testserver"
.SetProperty "Instance", "sdemss"
.SetProperty "Database", "sde"
' Ignored with ArcSDE for Oracle
.SetProperty "user", "sde"
.SetProperty "password", "go"
.SetProperty "version", "sde.DEFAULT"
End With
Set pFact = New SdeWorkspaceFactory
Set pWorkspace = pFact.Open(pPropset, Me.hWnd)
Dim pFeatureWorkspace As IFeatureWorkspace
Set pFeatureWorkspace = pWorkspace
Dim pFeatureClass As IFeatureClass
Set pFeatureClass = pFeatureWorkspace.OpenFeatureClass("parcels")

2 comments:

ncollins said...

Does anyone out there have an example in C#?
Here is mine and I have having problems understanding what my INSTANCE is or make sure I have all the properties set right? Do I need the full path to my feature class?

IPropertySet pPropset = new PropertySetClass();
IWorkspaceFactory pWorkFact;
IWorkspace pWorkSpace;

pPropset.SetProperty("SERVER", upigismain);
pPropset.SetProperty("INSTANCE", sdencollins);
pPropset.SetProperty("DATABASE", SDE);
pPropset.SetProperty("USER", ncollins);
pPropset.SetProperty("PASSWORD", ncollins);
pPropset.SetProperty("VERSION", SDE.Default);

pWorkFact = new SdeWorkspaceFactoryClass();
pWorkSpace = pWorkFact.Open(pPropset, ncollins.hWnd);
IFeatureWorkspace pFeatureWorkspace;
pFeatureWorkspace = pWorkSpace;
IFeatureClass pFeatureClass;
pFeatureClass = pFeatureWorkspace.OpenFeatureClass("UP.AVL.Location");

Manoj Singh said...

Hi nicollins

Instance are the port of your SDE connection. for example 5151 is the port of you DB.
Please let me know in details if you have any issue in arcobject.

Regards
Manoj Singh
You can email me at manojsinghrana@gmail.com