douglas.robbie

Append.Execute works in FileGDB but not SDE?

Discussion created by douglas.robbie on Sep 18, 2012
Hi,

I am creating a suite of Add-Ins and this on backs up a selected layer. It works fine with a FileGDB but I get an COM Exception with an SDE. I am using an ArcEditor License and the code will create and delete the feature class in the SDE but it won't append. Here is the exception.

[ATTACH=CONFIG]17776[/ATTACH]

        public static IWorkspace FileGdbWorkspaceFromPath(String path)
        {
            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
            return workspaceFactory.OpenFromFile(path, 0);
        }


        public IWorkspace WorkgroupArcSdeWorkspaceFromString(string connectionString)
        {
            try
            {
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");
                IWorkspaceFactory2 workspaceFactory2 = (IWorkspaceFactory2)Activator.CreateInstance(factoryType);
                return workspaceFactory2.OpenFromString(connectionString, 0);
            }
            catch (Exception exc)
            {
                MessageBox.Show(Convert.ToString(exc));
                return null;
            }
        }

        public IFeatureClass GetFeatureClassOfSelectedFeatureLayer(IFeatureLayer featureLayer)
        {
            IFeatureClass featureClass = featureLayer.FeatureClass;
            return featureClass;
        }

        protected override void OnClick()
        {
            //IWorkspace workSpace = FileGdbWorkspaceFromPath(@"G:\PROJECTS\SCHOOL_SAFETY_MAPPING_APPLICATION_20120606\DATA\SchoolSafety.gdb");
            string connectionString = "SERVER=dotdevgissql01;DATABASE=GISAPP_SCHOOLSAFETY;INSTANCE=sde:sqlserver:dotdevgissql01;AUTHENTICATION_MODE=DBMS;USER=...;PASSWORD=...;VERSION=dbo.DEFAULT";
            IWorkspace workSpace = WorkgroupArcSdeWorkspaceFromString(connectionString);
            CreateFeatureClass(workSpace, "SelectedLayerBU");
        }

        public void CreateFeatureClass(IWorkspace workspace, String featureClassName)
        {
            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;

            IWorkspace2 pWorkspace2 = workspace as IWorkspace2;

            ////Delete the Feature Class if it already exists////
            if (pWorkspace2.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, "SelectedLayerBU"))
            {
                FeatureClass featureC = (FeatureClass)featureWorkspace.OpenFeatureClass("SelectedLayerBU");
                IDataset dataSet;
                //ISchemaLock schemaLock = (ISchemaLock)featureC;
                dataSet = featureC;
                dataSet.Delete();
                //schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);
            }

            IFeatureClass featureSelected = GetFeatureClassOfSelectedFeatureLayer((IFeatureLayer)ArcMap.Document.SelectedLayer);
           
            try
            {
                
                featureWorkspace.CreateFeatureClass("SelectedLayerBU", featureSelected.Fields, featureSelected.CLSID, featureSelected.EXTCLSID, featureSelected.FeatureType, featureSelected.ShapeFieldName, null);
                Geoprocessor gp = new Geoprocessor();
                FeatureClass featureClassNew = (FeatureClass)featureWorkspace.OpenFeatureClass("SelectedLayerBU");

                IDataset dataSet2;
                dataSet2 = featureClassNew;
                string connectionString = "SERVER=dotdevgissql01;DATABASE=GISAPP_SCHOOLSAFETY;INSTANCE=sde:sqlserver:dotdevgissql01;AUTHENTICATION_MODE=DBMS;USER=...;PASSWORD=...;VERSION=dbo.DEFAULT";
                gp.SetEnvironmentValue("workspace", connectionString);
                //gp.SetEnvironmentValue("workspace", @"G:\PROJECTS\SCHOOL_SAFETY_MAPPING_APPLICATION_20120606\DATA\SchoolSafety.gdb");
                
                Append append = new Append(); //this tool uploads the feature class
                append.inputs = featureSelected;
                
                append.target = dataSet2;
                
                gp.AddOutputsToMap = false;

                gp.Execute(append, null); 
            }


Thanks for any insight,
Robbie

Attachments

Outcomes