Select to view content in your preferred language

GETTING DATASETS BY PASSING CONCNETION PROPERTIES

889
3
02-25-2013 12:45 AM
ChaitanyaPeddinty
Deactivated User
I am trying to get all dataset names and feature class available in ARC sde..... i WROTE BELOW CODE..... bUT i AM GETTING ERROR LIKE oPERATION FAILED.. CAN ANY ONE SUGGEST ME THE SOLUTION...





IWorkspaceFactory pWF = new ESRI.ArcGIS.DataSourcesGDB.SdeWorkspaceFactoryClass();
                IPropertySet pPropertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass();
                pPropertySet.SetProperty("SERVER", "172.16.8.56");
                pPropertySet.SetProperty("INSTANCE", "1522");
                pPropertySet.SetProperty("DATABASE", "@C:\\Documents and Settings\\ABC\\Application Data\\ESRI\\ArcCatalog");
                pPropertySet.SetProperty("USER", "ABC");
                pPropertySet.SetProperty("PASSWORD", "ABC");
                pPropertySet.SetProperty("VERSION", "ABC");
                IWorkspace pWorkSpace = pWF.Open(pPropertySet, 0);                             
                IEnumDataset enumDataset = pWorkSpace.get_Datasets(esriDatasetType.esriDTAny);
                IDataset pDataSet = enumDataset.Next();
                while (pDataSet != null)
                {
                    string DSetName = pDataSet.Name;
                }
0 Kudos
3 Replies
LeoDonahue
Deactivated User
There is an ESRI sample that does this.  If you are running Java, you'll find the example in your ArcGIS Project wizzard.

here is a code fragment from that sample:

    /**
     * Connect to ArcSDE and initiate printing meta-data for feature classes and sde tables.
     */
    private static void connectToSDE(){

        try {

            // Create a propertySet that contains the connection information to ArcSDE
            IPropertySet propertySet = new PropertySet();
            propertySet.setProperty("SERVER", "server name");
            propertySet.setProperty("INSTANCE", "instance name");
            propertySet.setProperty("DATABASE", "database name");
            propertySet.setProperty("USER", "user name");
            propertySet.setProperty("PASSWORD", "user password");
            propertySet.setProperty("VERSION", "sde.DEFAULT");

            // Create a SdeWorkspaceFactory and open it
            IWorkspaceFactory sdeworkspaceFactory = new SdeWorkspaceFactory();
            IWorkspace workspace = new Workspace(sdeworkspaceFactory.open(propertySet, 0));
            
            // ---------------------------------------------------------------------------------------
            // Iterate over all feature classes : esriDTFeatureClass
            // ---------------------------------------------------------------------------------------

            // Get the collection of featureclass data set names in the database and display their names.
            IEnumDatasetName dsFeatureClassNames = workspace.getDatasetNames(esriDatasetType.esriDTFeatureClass);
            
            // Add the data set names to an ArrayList that we will sort as a Collection
            ArrayList<String> featureclassDatasetNames = new ArrayList<String>();
            IDatasetName fcName = dsFeatureClassNames.next();
            while (fcName != null){
                featureclassDatasetNames.add(fcName.getName());
                fcName = dsFeatureClassNames.next();
            }
            
            // Sort the ArrayList
            Collections.sort(featureclassDatasetNames);
            
            // Iterate over the set and call the displayFeatureClassMetadata method
            for(Object y : featureclassDatasetNames){
                writer.append(y.toString());
                writer.append("\r\n");
                writer.append("--------------------");
                writer.append("\r\n");
                displayFeatureClassMetadata(workspace, y.toString());
            }
            // ---------------------------------------------------------------------------------------
            
            // ---------------------------------------------------------------------------------------
            // Iterate over all tables : esriDTTable
            // ---------------------------------------------------------------------------------------
            
            // Get the collection of Table data set names in the database and display their names.
            IEnumDatasetName dsTableNames = workspace.getDatasetNames(esriDatasetType.esriDTTable);
            
            // Add the data set names to an ArrayList that we will sort as a Collection
            ArrayList<String> tableDatasetNames = new ArrayList<String>();
            IDatasetName name = dsTableNames.next();
            while (name != null){
                tableDatasetNames.add(name.getName());
                name = dsTableNames.next();
            }
            
            // Sort the ArrayList
            Collections.sort(tableDatasetNames);
            
            // Iterate over the set and call the displayTableMetadata method
            for(Object y : tableDatasetNames){
                writer.append(y.toString());
                writer.append("\r\n");
                writer.append("--------------------");
                writer.append("\r\n");
                displayTableMetadata(workspace, y.toString());
            }
            // ---------------------------------------------------------------------------------------

        } catch (AutomationException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
0 Kudos
ChaitanyaPeddinty
Deactivated User
Hi.... Thank You Very Much for your Reply..
0 Kudos
AlexanderGray
Honored Contributor
You should mark Leo's post as the answer if it answered your question
0 Kudos