AnsweredAssumed Answered

SDEWorkspaceFactory returning wrong workspace

Question asked by andrewpboyle on Jun 21, 2013
Latest reply on Jun 25, 2013 by andrewpboyle
I'm trying to write an ArcCatalog 10.1 Add-in where you select a folder in ArcCatalog and click a button that kicks off a process that searches through the directory for layer files and switches the connection information if it meets certain requirements.  I'm running into an issue using the SDEWorkspaceFactory class in the following code where I try to change the connection information:

Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory"); IWorkspaceFactory2 workspaceFactory = (IWorkspaceFactory2)Activator.CreateInstance(factoryType); IWorkspace workspace = workspaceFactory.Open(connectionPropertySet, ArcCatalog.Application.hWnd); IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(datasetName.Name); if (featureClass == null) {     return false; } featureLayer.FeatureClass = featureClass;


The issue is that I supply workspaceFactory.Open with the following connection properties.

SERVER: *myServer*
INSTANCE: *instance2*
USER: *user*
PASSWORD: *password*
AUTHENTICATION_MODE: *authentication mode*
VERSION: *version*

The workspace I get back does not always have matching connection properties.  Instead it has...

SERVER: *myServer*
INSTANCE: *instance1*
USER: *user*
PASSWORD: *password*
AUTHENTICATION_MODE: *authentication mode*
VERSION: *version*
IS_GEODATABASE: *is geodatabase*
CONNPROP-REV: *connprop-rev*

Since it returns the wrong instance, the call featureWorkspace.OpenFeatureClass(datasetName.Name) throws an exeption since the feature we are looking for does not exist in the specified instance.  All the other connection properties are fine.

I'll note that this is not a consistent problem.  Sometimes I pass *instance1* and get *instance2* or vice versa and sometimes I get the correct instance.  Usually, running the tool a couple times switches all the files.

The tool is written in C# using ArcObjects 10.1 and .NET Framework 3.5

Outcomes