Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the proper way to declare an ArcSDE workspace for Geoprocessing tools in c# .net?

I am using ArcGIS 10.1 SDE (MS SQL) on SQL Server 2008. I want to write code so that every night the server will fire a program and compress one of my ArcSDE databases. I thought I could do this in c# using the Compress tool in the data management namespace but have run into a snag.

I am told my workspace is invalid. Esri help docs are not helpful, as they just show generic help and my internet search has lead nowhere.

Can anyone tell me how to define an ArcSDE workspace in 10.1 in net?

Right now I am using @"Database Connections\CME.sde". Here is the error:

Executing: Compress "Database Connections\CME.sde" Start Time: Fri Oct 12 13:40:47 2012 Failed to execute. Parameters are not valid. ERROR 000837: The workspace is not the correct workspace type. Failed to execute (Compress).

What should I type for the in_workspace?

private void button1_Click(object sender, EventArgs e)

            Compress Compressor = new Compress();
            object in_workspace = @"Database Connections\CME.sde";

            Compressor.in_workspace = in_workspace;

            Geoprocessor GP = new Geoprocessor();
            RunTool(GP, Compressor, null);

        private static void RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC)

            // Set the overwrite output option to true
            geoprocessor.OverwriteOutput = true;

            // Execute the tool            
                geoprocessor.Execute(process, null);

            catch (Exception err)
        private static void ReturnMessages(Geoprocessor gp)
            if (gp.MessageCount > 0)
                for (int Count = 0; Count <= gp.MessageCount - 1; Count++)


share|improve this question
up vote 3 down vote accepted

this code returns an SDE workspace, hopes can help

    // For example, connectionFile = @"C:\myData\Connection to Kona.sde".
    private static IWorkspace ArcSdeWorkspaceFromFile(String connectionFile)
        Type factoryType = Type.GetTypeFromProgID(
        IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance
        return workspaceFactory.OpenFromFile(connectionFile, 0);

share|improve this answer
Thanks, that did indeed work – Nick Nov 15 '12 at 0:21
I used that for 10.0 also. – Chris P Oct 31 '13 at 13:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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