sx5181

Error convert shp to sde

Discussion created by sx5181 on Oct 1, 2013
I want converted shapefile into SDE database (in SQL server), with gdb it works stable but sde it error.
Please help me !
my source code and error

public static void LoadDemo()
        {
            try
            {
               
                IWorkspaceName sourceWorkspaceName = (IWorkspaceName)new WorkspaceName();
                sourceWorkspaceName.PathName = @"C:\Crip\trichluc";
                sourceWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory.1";
             
                IWorkspaceName targetWorkspaceName;
                Type t = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory.1");
                IWorkspaceFactory pFactory = (IWorkspaceFactory)Activator.CreateInstance(t);
                if (File.Exists(@"C:\Crip1\load.sde"))
                {
                    IWorkspace workspace = pFactory.OpenFromFile(@"C:\Crip1\load.sde", 0);
                    IDataset ids = (IDataset)workspace;
                    targetWorkspaceName = (IWorkspaceName)ids.FullName;
                }
                else
                {
                    IPropertySet propertySet = new PropertySetClass();
                    propertySet.SetProperty("SERVER", "hpserver");
                    propertySet.SetProperty("INSTANCE", "5151");
                    propertySet.SetProperty("DATABASE", "sde");
                    propertySet.SetProperty("USER", "sde");
                    propertySet.SetProperty("PASSWORD", "12345678");
                    propertySet.SetProperty("VERSION", "dbo.DEFAULT");
                    targetWorkspaceName = pFactory.Create(@"C:\Crip1", "load.sde", propertySet, 0);
                }


                // Create a name object for the source feature class. 
                IFeatureClassName sourceFeatureClassName = (IFeatureClassName)new FeatureClassName();
                IDatasetName sourceDatasetName = (IDatasetName)sourceFeatureClassName;
                sourceDatasetName.WorkspaceName = sourceWorkspaceName;
                sourceDatasetName.Name = "87884606.shp";

                IFeatureDatasetName featDSName = new FeatureDatasetName() as IFeatureDatasetName;
                IDatasetName DSName = (IDatasetName)featDSName;
                DSName.WorkspaceName = targetWorkspaceName;
                DSName.Name = "test";

                IFeatureClassName targetFeatureClassName = (IFeatureClassName)new FeatureClassName();
                IDatasetName targetDatasetName = targetFeatureClassName as IDatasetName;
                targetDatasetName.WorkspaceName = targetWorkspaceName;
                targetDatasetName.Name = "load_demo";


                // Open the source feature class to get field definitions. 
                IName sourceName = (IName)sourceDatasetName;
                IFeatureClass sourceFeatureClass = (IFeatureClass)sourceName.Open();

                // Open the two workspaces for the field validator. 
                IName sourceIName = (IName)sourceWorkspaceName;
                IName targetIName = (IName)targetWorkspaceName;
                IWorkspace sourceWorkspace = (IWorkspace)sourceIName.Open();
                IWorkspace targetWorkspace = (IWorkspace)targetIName.Open();

                // Use a field checker for field validation.
                IFieldChecker fieldChecker = new FieldChecker();
                IFields sourceFields = sourceFeatureClass.Fields;
                fieldChecker.InputWorkspace = sourceWorkspace;
                fieldChecker.ValidateWorkspace = targetWorkspace;
                IEnumFieldError enumFieldError = null;
                IFields outputFields = null;
                fieldChecker.Validate(sourceFields, out enumFieldError, out outputFields);

               
                // If any field validation errors occurred, they can be viewed at this point. 

                // Get the GeometryDef from the source feature class and modify it. 
                // Note that this only modifies the object in memory, and will not effect the source data. 
                int shapeFieldIndex = sourceFeatureClass.FindField(sourceFeatureClass.ShapeFieldName);
                IField shapeField = sourceFields.get_Field(shapeFieldIndex);
                IGeometryDef geometryDef = shapeField.GeometryDef;
                IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
                geometryDefEdit.GridCount_2 = 1;
                geometryDefEdit.set_GridSize(0, 1500000);

                // Load the feature class. 
                IFeatureDataConverter featureDataConverter = (IFeatureDataConverter)new FeatureDataConverter();
                try
                {

                    featureDataConverter.ConvertFeatureClass(sourceFeatureClassName,
                    null, featDSName, targetFeatureClassName, geometryDef, outputFields, "", 1000, 0);

                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.ToString());
                    //throw;
                }


                // If any invalid features were encountered during conversion, they can be 
                // displayed by iterating through the enumInvalidObject enumerator. 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

        }


[ATTACH=CONFIG]27928[/ATTACH]

Attachments

Outcomes