Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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            
            try
            {
                geoprocessor.Execute(process, null);
                ReturnMessages(geoprocessor);

            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message); 
                ReturnMessages(geoprocessor);
            }
        }
        private static void ReturnMessages(Geoprocessor gp)
        {
            if (gp.MessageCount > 0)
            {
                for (int Count = 0; Count <= gp.MessageCount - 1; Count++)
                {
                  Console.WriteLine(gp.GetMessage(Count));

                }
            }

        }
    }
share|improve this question

1 Answer 1

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(
            "esriDataSourcesGDB.SdeWorkspaceFactory");
        IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance
            (factoryType);
        return workspaceFactory.OpenFromFile(connectionFile, 0);

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

Your Answer

 
discard

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.