(C#) ArcCatalog Add-in: Cannot open feature classes unless physically connected

402
0
03-18-2013 05:34 AM
KevinYanuk
Occasional Contributor
I am writing a simple ArcCatalog Add-in which connects to an SDE database, and performs a clip of a set of feature classes (set in a config file) based on a few input parameters (dataset, clipping feature, output location).

Everything works fine only if I am connected physically via the connection file in ArcCatalog.  Otherwise, I am getting an exception claiming the Input Features do not exist or are no supported.


However, if I double click the connection in the Catalog Tree, and connect, the application runs fine, and does the clipping successfully.

The credentials are hardcoded into a configuration file and I connect using the standard way to connect from the ArcGIS help:


        public static IFeatureWorkspace ConnectToSDE()
        {
            try
            {
                IPropertySet propertySet = new PropertySetClass();
                foreach (XmlNode dbprop in ConfigurationHelper.DatabaseNodes)
                {
                    propertySet.SetProperty("DB_CONNECTION_PROPERTIES", "");
                    propertySet.SetProperty("INSTANCE", dbprop.dbInstance());
                    propertySet.SetProperty("USER", dbprop.dbUser());
                    propertySet.SetProperty("PASSWORD", dbprop.dbPassword());
                    propertySet.SetProperty("DATABASE", dbprop.dbDatabase());
                    propertySet.SetProperty("VERSION", dbprop.dbVersion());
                }

                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");
                IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                _sdeWorkspace = (IFeatureWorkspace)workspaceFactory.Open(propertySet, 0);
                return (IFeatureWorkspace)workspaceFactory.Open(propertySet, 0);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace);
                return null;
            }
        }


I connect via form load.

I have used this method before in a stand-alone application, and have never had this issue before.
0 Kudos
0 Replies