I'm trying to open a workspace from the IWorkspaceFactory interface. Here's what I'm trying at the moment:

ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (ESRI.ArcGIS.Carto.IFeatureLayer)pLayer;
ESRI.ArcGIS.Geodatabase.IFeatureClass oldFeatureClass = featureLayer.FeatureClass;

IPropertySet propertySet = new PropertySetClass();
propertySet.SetProperty("INSTANCE", newData.instance); //sde:sqlserver:(servername)
propertySet.SetProperty("DATABASE", newData.database); //(databasename)
propertySet.SetProperty("AUTHENTICATION_MODE", newData.autMode); //OSA
propertySet.SetProperty("VERSION", newData.version); //sde.DEFAULT

Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");
IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);

IWorkspace workspace = workspaceFactory.Open(propertySet, 0);

For my properties I have also tried the following:

propertySet.SetProperty("SERVER", serverName);
propertySet.SetProperty("INSTANCE", "sde:sqlserver:(database)");          
propertySet.SetProperty("DATABASE", "SDE");
propertySet.SetProperty("AUTHENTICATION_MODE", newData.autMode); //OSA
propertySet.SetProperty("VERSION", newData.version); //sde.DEFAULT

I know that the property settings are the issue as when I try using

propertySet.SetProperty("SERVERINSTANCE", serverName);

It shows the new connection dialog. enter image description here

To give you an idea of my values, I consider Instance in this window to be the server name. I consider database to be the database name. This should give you an idea of what I'm setting my values as.

Is there a property value that I'm missing or a value that is incorrect?

Edit: Based on comment I have added a revised property set that brings up the database connection screen still, but everything is filled out. However, users can still edit the authentication type, which for some people may be confusing. I would like to just skip that screen and have it connect without any user input.

propertySet.SetProperty("SERVERINSTANCE", "(instance)\\(database)");
propertySet.SetProperty("DBCLIENT", "SQLServer");
propertySet.SetProperty("VERSION", newData.version); //sde.DEFAULT
propertySet.SetProperty("AUTHENTICATION_MODE", newData.autMode); //OSA

I have tried entering my Operating system authentication credentials under

propertySet.SetProperty("user", "username");
propertySet.SetProperty("password", "password");

However, this still shows the screen and the credentials aren't filled in on the form. (The screen I'm referring to is the database connection form screenshot above.)

  • Your instance parameter format looks wrong. Look at this thread... gis.stackexchange.com/questions/104656/… Nov 21, 2015 at 0:22
  • This got me pretty close to what I'm needing. The dialogue still shows for entering a database connection. Everything is filled out though they could just click okay, but I feel like the ability to change authentication type might confuse some users. Is there a way to skip this? I've edited my post with the new property set. Nov 23, 2015 at 16:15
  • Cool. I know that dialog, not sure what to do about it. You may try the IWorkspaceFactory.OpenFromFile method and see if the dialog shows up. If that works it would mean deploying a connection file using OSA with your script. Nov 24, 2015 at 23:33
  • I got it working. If you submit your original comment as an answer, I'll mark it as the answer so you get the credit. Dec 11, 2015 at 16:27

2 Answers 2


To close the question...(thanks Josh!)

Your instance parameter format looks wrong. Look at this link for support: Connecting to SQL Server Geodatabase using ArcObject in C#

You may try the IWorkspaceFactory.OpenFromFile method. If that works better it would mean deploying a connection file using OSA with your script.


I agree that setting workspace properties is a bit tricky. However I see some mistakes with your settings. e.g. your instance must be like "sde:sqlserver:serverName" and not "sde:sqlserver:dbName".

This snippet can help you out:

pPropertySet.SetProperty("INSTANCE", "sde:sqlserver:serverName");
pPropertySet.SetProperty("DATABASE", "dbname");
pPropertySet.SetProperty("AUTHENTICATION_MODE", "OSA"); 
pPropertySet.SetProperty("DBCLIENT", "SQLServer");
pPropertySet.SetProperty("VERSION", "sde.DEFAULT"); //can be any other version that the user has read access to.
//pPropertySet.SetProperty("USER", "userName");   not needed (OSA)
//pPropertySet.SetProperty("PASSWORD", "password"); not needed (OSA)

and note that when you are using direct connection, SERVER property MUST not be declared!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.