Esempio n. 1
0
        private void TestConn_Click(object sender, EventArgs e)
        {
            Success = false;
            try
            {
                IWorkspace Currworkspace = null;
                string     IP            = textEdit1.Text;
                string     Instance      = textEdit2.Text;
                string     version       = textEdit6.Text;
                string     database      = textEdit3.Text;
                string     user          = textEdit7.Text;
                string     password      = textEdit4.Text;
                string     ConnCname     = textEdit5.Text;

                IPropertySet propertyset = new ESRI.ArcGIS.esriSystem.PropertySetClass();
                propertyset.SetProperty("Server", IP);
                propertyset.SetProperty("instance", Instance);
                propertyset.SetProperty("database", database);
                propertyset.SetProperty("user", user);
                propertyset.SetProperty("password", password);
                propertyset.SetProperty("version", version);
                IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactory();
                Currworkspace = workspaceFactory.Open(propertyset, 0);
                MessageBox.Show("连接成功!");
                Success = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("连接失败!");
                Success = false;
                string Error = ex.Message;
            }
        }
Esempio n. 2
0
        private static byte[] ReproHandler(NameValueCollection boundVariables,
                                           JsonObject operationInput,
                                           string outputFormat,
                                           string requestProperties,
                                           out string responseProperties)
        {
            responseProperties = null;

            // connect to SDE
            var propertySet = new PropertySet();

            propertySet.SetProperty("SERVER", "");
            propertySet.SetProperty("INSTANCE", "");
            propertySet.SetProperty("DATABASE", "");
            propertySet.SetProperty("USER", "");
            propertySet.SetProperty("PASSWORD", "");
            propertySet.SetProperty("VERSION", "sde.DEFAULT");

            var workspaceFactory = new SdeWorkspaceFactory();
            var workspace        = workspaceFactory.Open(propertySet, 0);

            var featureWorkspace = workspace as IRasterWorkspaceEx;

            // open the dem in an SDE Raster Dataset with a Raster Attribute Table
            // our raster table has the schema objectid, value, count, feet
            var featureClass = featureWorkspace.OpenRasterDataset("DEM_10Meter");

            var rasterLayer = new RasterLayer();

            rasterLayer.CreateFromDataset(featureClass);

            var table    = rasterLayer as ITable;
            var identify = rasterLayer as IIdentify;

            // create a point that will intersect your raster
            IPoint point = null;

            var results = identify.Identify(point);
            var item    = results.Element[0] as IRasterIdentifyObj2;

            // this will return 1 for value since object id is 0, count is 2 and feet is 3
            var valueIndex = table.FindField("VALUE");

            string property;
            string value;

            item.GetPropAndValues(valueIndex, out property, out value);

            // when using the index 1, the property will be object id and the value will be the object id
            // when querying for feet, the correct property and value are returned.

            // The correct way
            var    item2 = item as IIdentifyObject;
            object props;
            object values;

            item2.PropertySet.GetAllProperties(out props, out values);

            return(Encoding.UTF8.GetBytes(property + ": " + value));
        }
Esempio n. 3
0
        /// <summary>
        /// 通过权限信息取得IWorkspace
        /// </summary>
        /// <returns>工作空间</returns>
        public IWorkspace GetWorkspace()
        {
            IWorkspaceFactory pWorkSpaceFactory = null;
            IPropertySet      pPropertySet      = null;

            try
            {
                pWorkSpaceFactory = new SdeWorkspaceFactory();
                pPropertySet      = new PropertySet();

                //设置属性集参数
                pPropertySet.SetProperty("Server", Server);
                pPropertySet.SetProperty("Instance", Service);
                pPropertySet.SetProperty("Database", Datasource);
                pPropertySet.SetProperty("User", User);
                pPropertySet.SetProperty("Password", Password);
                pPropertySet.SetProperty("Version", Version);

                //返回打开的工作空间
                return(pWorkSpaceFactory.Open(pPropertySet, 0));
            }
            catch (Exception)
            {
                pWorkSpaceFactory = null;
                pPropertySet      = null;

                //异常后返回空值
                return(null);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Open a feature class from an SDE Workspace
        /// </summary>
        /// <param name="conFilePath">string path to the SDE connection file</param>
        /// <param name="fcName">Feature class name</param>
        /// <param name="fdsName">Optional name of feature dataset</param>
        /// <param name="versionName">Optional version name, defaults to the version specified by the connection file</param>
        /// <returns></returns>
        public static IFeatureClass openFeatureClassFromSDE(string conFilePath, string fcName, string fdsName = "", string versionName = "")
        {
            IFeatureClass featClass = null;
            IWorkspaceFactory factory = new SdeWorkspaceFactory();
            IPropertySet props = factory.ReadConnectionPropertiesFromFile(conFilePath);
            if (versionName != "")
            {
                props.SetProperty("VERSION", versionName);
            }
            IWorkspace workspace = factory.Open(props, 0);

            IFeatureWorkspace featWorkspace = (IFeatureWorkspace)workspace;
            if (fdsName != "")
            {
                IFeatureDataset featdataset = featWorkspace.OpenFeatureDataset(fdsName);
                IFeatureWorkspace datasetWorkspace = (IFeatureWorkspace)featdataset.Workspace;
                featClass = datasetWorkspace.OpenFeatureClass(fcName);
                //featClass = featWorkspace.OpenFeatureClass(fdsName + "\\" + fcName);
            }
            else
            {
                featClass = featWorkspace.OpenFeatureClass(fcName);
            }
            return featClass;
        }
Esempio n. 5
0
        public static IWorkspace OpenWorkspace(IPropertySet ipropertySet_0)
        {
            IWorkspace        workspace = null;
            IWorkspaceFactory factory;
            Exception         exception;

            if (ipropertySet_0.Count == 1)
            {
                object obj2;
                object obj3;
                string str2 = "";
                ipropertySet_0.GetAllProperties(out obj2, out obj3);
                if (((string[])obj2)[0] == "DATABASE")
                {
                    str2 = System.IO.Path.GetExtension(((object[])obj3)[0].ToString()).ToLower();
                }
                if (str2 == ".mdb")
                {
                    factory = new AccessWorkspaceFactory();
                    try
                    {
                        workspace = factory.Open(ipropertySet_0, 0);
                    }
                    catch (Exception exception1)
                    {
                        exception = exception1;
                        MessageBox.Show(exception.Message);
                    }
                    return(workspace);
                }
                if (str2 == ".gdb")
                {
                    factory = new FileGDBWorkspaceFactory();
                    try
                    {
                        workspace = factory.Open(ipropertySet_0, 0);
                    }
                    catch (Exception exception2)
                    {
                        exception = exception2;
                        MessageBox.Show(exception.Message);
                    }
                }
                return(workspace);
            }
            factory = new SdeWorkspaceFactory();
            try
            {
                workspace = factory.Open(ipropertySet_0, 0);
            }
            catch (Exception exception3)
            {
                exception = exception3;
                MessageBox.Show(exception.Message);
            }
            return(workspace);
        }
Esempio n. 6
0
        public static IWorkspace OpenWorkspace(IPropertySet ipropertySet_0)
        {
            object            obj;
            object            obj1;
            IWorkspaceFactory sdeWorkspaceFactoryClass;
            IWorkspace        workspace = null;

            if (ipropertySet_0.Count != 1)
            {
                sdeWorkspaceFactoryClass = new SdeWorkspaceFactory();
                try
                {
                    workspace = sdeWorkspaceFactoryClass.Open(ipropertySet_0, 0);
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }
            }
            else
            {
                string str   = "";
                string lower = "";
                ipropertySet_0.GetAllProperties(out obj, out obj1);
                if (((string[])obj)[0] == "DATABASE")
                {
                    str   = ((object[])obj1)[0].ToString();
                    lower = System.IO.Path.GetExtension(str).ToLower();
                }
                if (lower == ".mdb")
                {
                    sdeWorkspaceFactoryClass = new AccessWorkspaceFactory();
                    try
                    {
                        workspace = sdeWorkspaceFactoryClass.Open(ipropertySet_0, 0);
                    }
                    catch (Exception exception1)
                    {
                        MessageBox.Show(exception1.Message);
                    }
                }
                else if (lower == ".gdb")
                {
                    sdeWorkspaceFactoryClass = new FileGDBWorkspaceFactory();
                    try
                    {
                        workspace = sdeWorkspaceFactoryClass.Open(ipropertySet_0, 0);
                    }
                    catch (Exception exception2)
                    {
                        MessageBox.Show(exception2.Message);
                    }
                }
            }
            return(workspace);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            schemaFile        = textBox1.Text;
            targetGeodatabase = textBox2.Text;

            IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactory();

            IWorkspace targetWorkspace = workspaceFactory.OpenFromFile(targetGeodatabase, 0);

            ListSchemaChanges(targetWorkspace, schemaFile, true);
            MessageBox.Show("Successfully Updated!");
        }
Esempio n. 8
0
        public override IWorkspace Connect()
        {
            var propertySet = new PropertySet();
            propertySet.SetProperty("SERVER", Information.ServerName);
            propertySet.SetProperty("INSTANCE", Information.InstanceName);
            propertySet.SetProperty("DATABASE", Information.DatabaseName);
            propertySet.SetProperty("USER", Information.Name);
            propertySet.SetProperty("PASSWORD", Information.Password);
            propertySet.SetProperty("VERSION", Information.Version);

            var workspaceFactory = new SdeWorkspaceFactory();
            var workspace = workspaceFactory.Open(propertySet, 0);

            return workspace;
        }
Esempio n. 9
0
        public override IWorkspace Connect()
        {
            var propertySet = new PropertySet();

            propertySet.SetProperty("SERVER", Information.ServerName);
            propertySet.SetProperty("INSTANCE", Information.InstanceName);
            propertySet.SetProperty("DATABASE", Information.DatabaseName);
            propertySet.SetProperty("USER", Information.Name);
            propertySet.SetProperty("PASSWORD", Information.Password);
            propertySet.SetProperty("VERSION", Information.Version);

            var workspaceFactory = new SdeWorkspaceFactory();
            var workspace        = workspaceFactory.Open(propertySet, 0);

            return(workspace);
        }
Esempio n. 10
0
 /// <summary>
 /// 获取SDE数据库工作空间
 /// </summary>
 /// <param name="sdePath">.sde文件</param>
 /// <returns></returns>
 public static IWorkspace GetSdeWorkspace(string sdePath)
 {
     if (sdePath == "" || !sdePath.EndsWith(".sde") || !File.Exists(sdePath))
     {
         throw new Exception(string.Format("请选择sde文件"));
     }
     try
     {
         IWorkspaceFactory2 wf        = new SdeWorkspaceFactory() as IWorkspaceFactory2;
         IWorkspace         workspace = wf.OpenFromFile(sdePath, 0);
         return(workspace);
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打开SDE数据库失败"), ex);
     }
 }
Esempio n. 11
0
 /// <summary>
 /// 获取SDE数据库工作空间
 /// </summary>
 /// <param name="propertySet">数据库连接信息</param>
 /// <returns></returns>
 private static IWorkspace GetSdeWorkspace(IPropertySet propertySet)
 {
     if (propertySet == null)
     {
         throw new Exception(string.Format("参数IPropertySet不能为空"));
     }
     try
     {
         IWorkspaceFactory2 wf        = new SdeWorkspaceFactory() as IWorkspaceFactory2;
         IWorkspace         workspace = wf.Open(propertySet, 0);
         return(workspace);
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("打开SDE数据库失败"), ex);
     }
 }
Esempio n. 12
0
        /// <summary>
        /// 根据连接信息获取工作空间
        /// </summary>
        /// <param name="clsConninfo">用于提供连接信息的类</param>
        /// <returns>工作空间</returns>
        public IWorkspace GetWorkspace(ClsConnectInfo clsConninfo)
        {
            IWorkspaceFactory pWorkSpaceFactory = null;
            IPropertySet      pPropertySet      = null;

            pPropertySet      = new PropertySet();
            pWorkSpaceFactory = new SdeWorkspaceFactory();

            //根据连接信息的对应信息设置属性集
            pPropertySet.SetProperty("Server", clsConninfo.Server);
            pPropertySet.SetProperty("Instance", clsConninfo.Service);
            pPropertySet.SetProperty("User", clsConninfo.User);
            pPropertySet.SetProperty("Password", clsConninfo.Password);
            pPropertySet.SetProperty("Version", clsConninfo.Version);

            //返回打开的工作空间
            return(pWorkSpaceFactory.Open(pPropertySet, 0));
        }
Esempio n. 13
0
        private void button1_Click(object sender, EventArgs e)
        {
            // SDE空间连接属性
            IPropertySet propertySet = new PropertySetClass();

            propertySet.SetProperty("server", this.textBox1.Text);
            propertySet.SetProperty("instance", this.textBox2.Text);
            propertySet.SetProperty("database", this.textBox3.Text);
            propertySet.SetProperty("user", this.textBox4.Text);
            propertySet.SetProperty("password", this.textBox5.Text);
            propertySet.SetProperty("version", "SDE.DEFAULT");
            IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactory();

            //打开SDE工作空间

            workspace = workspaceFactory.Open(propertySet, 0);
            MessageBox.Show("连接SDE空间数据库成功");
        }
Esempio n. 14
0
        public static IWorkspace OpenSDEGDB(string string_0)
        {
            IWorkspace        workspace = null;
            IWorkspaceFactory o         = new SdeWorkspaceFactory();

            try
            {
                workspace = o.OpenFromFile(string_0, 0);
            }
            catch (COMException exception)
            {
                MessageBox.Show("错误代码:" + exception.ErrorCode.ToString() + "\r\n" + exception.Message);
            }
            catch (Exception)
            {
            }
            ComReleaser.ReleaseCOMObject(o);
            o = null;
            return(workspace);
        }
Esempio n. 15
0
        public static IWorkspace OpenSDEGDB(string string_0)
        {
            IWorkspace        workspace = null;
            IWorkspaceFactory sdeWorkspaceFactoryClass = new SdeWorkspaceFactory();

            try
            {
                workspace = sdeWorkspaceFactoryClass.OpenFromFile(string_0, 0);
            }
            catch (COMException cOMException1)
            {
                COMException cOMException = cOMException1;
                int          errorCode    = cOMException.ErrorCode;
                MessageBox.Show(string.Concat("错误代码:", errorCode.ToString(), "\r\n", cOMException.Message));
            }
            catch (Exception exception)
            {
            }
            ComReleaser.ReleaseCOMObject(sdeWorkspaceFactoryClass);
            sdeWorkspaceFactoryClass = null;
            return(workspace);
        }
Esempio n. 16
0
        public ITable GetArcObjectsSdeTable(string server, string instance, string database, string version, string legendentabelle, string user = "", string password = "")
        {
            IWorkspaceFactory pFact;
            //IWorkspace pWorkspace;
            IFeatureWorkspace pFeatws;
            IPropertySet      pPropSet;//für eine SDE-Verbindung!!!
            ITable            pTable = null;

            //Write some Code for the SDE connection
            pPropSet = new PropertySet();
            pPropSet.SetProperty("SERVER", server);
            pPropSet.SetProperty("INSTANCE", instance);
            pPropSet.SetProperty("DATABASE", database);
            pPropSet.SetProperty("VESRSION", version);

            if (user != "" && password != "")
            {
                pPropSet.SetProperty("USER", user);
                pPropSet.SetProperty("PASSWORD", password);
                pPropSet.SetProperty("authentication_mode", "DBMS");
            }
            else
            {
                pPropSet.SetProperty("authentication_mode", "OSA");
            }

            pFact = new SdeWorkspaceFactory();
            try
            {
                pFeatws = (IFeatureWorkspace)pFact.Open(pPropSet, 0);
                pTable  = pFeatws.OpenTable(legendentabelle);
            }
            catch (Exception)
            {
                pTable = null;
            }
            return(pTable);
        }
Esempio n. 17
0
        public static IWorkspace GetSDEWorkspace(string sServerName, string sInstancePort, string sUserName,
                                                 string sPassword, string sVersionName)
        {
            IWorkspace   workspace;
            IPropertySet propertySetClass = new PropertySet();

            propertySetClass.SetProperty("Server", sServerName);
            propertySetClass.SetProperty("Instance", sInstancePort);
            propertySetClass.SetProperty("User", sUserName);
            propertySetClass.SetProperty("password", sPassword);
            propertySetClass.SetProperty("version", sVersionName);
            SdeWorkspaceFactory sdeWorkspaceFactoryClass = new SdeWorkspaceFactory();

            try
            {
                workspace = sdeWorkspaceFactoryClass.Open(propertySetClass, 0);
            }
            catch (Exception exception)
            {
                workspace = null;
            }
            return(workspace);
        }
Esempio n. 18
0
        public IWorkspace getSDEWorkspace(string server, string instance, string user, string password)
        {
            IPropertySet propertyset = new PropertySetClass();

            propertyset.SetProperty("server", server);
            propertyset.SetProperty("instance", instance);
            // propertyset.SetProperty("database", this.txt_database.Text);
            propertyset.SetProperty("user", user);
            propertyset.SetProperty("password", password);
            propertyset.SetProperty("version", @"SDE.DEFAULT");
            IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactory();
            IWorkspace        workspace        = null;

            try
            {
                workspace = workspaceFactory.Open(propertyset, 0);
            }
            catch (Exception eg)
            {
                throw eg;
            }
            return(workspace);
        }
Esempio n. 19
0
        public void AbrirGeodatabase()
        {
            IPropertySet propSet = null;

            propSet = new PropertySetClass();

            propSet.SetProperty("SERVER", ConnectionProperties.server);
            propSet.SetProperty("INSTANCE", ConnectionProperties.instance);
            propSet.SetProperty("USER", ConnectionProperties.user);
            propSet.SetProperty("PASSWORD", ConnectionProperties.password);
            propSet.SetProperty("VERSION", ConnectionProperties.version);

            IWorkspaceFactory pSdeFact = new SdeWorkspaceFactory();

            ws = pSdeFact.Open(propSet, 0);

            if (ws != null)
            {
                (ws as IWorkspaceEdit).StartEditing(false);
                (ws as IWorkspaceEdit).StartEditOperation();
            }
        }
Esempio n. 20
0
        private void ConnectWorkspace(string connectionString)
        {
            string            str = "";
            IWorkspaceFactory factory;

            foreach (string str2 in connectionString.Split(new char[] { ';' }))
            {
                string[] strArray3 = str2.Split(new char[] { '=' });
                switch (strArray3[0].ToLower())
                {
                case "dbclient":
                    dbclient = strArray3[1].ToLower();
                    break;

                case "server":
                    SDEServer = strArray3[1];
                    break;

                case "authentication_mode":
                    authentication_mode = strArray3[1].ToLower();
                    break;

                case "user":
                    SDEUser = strArray3[1];
                    break;

                case "password":
                    SDEPassword = strArray3[1];
                    break;

                case "version":
                    SDEVersion = strArray3[1];
                    break;

                case "database":
                    SDEDatabase = strArray3[1];
                    break;

                case "gdbname":
                    str = strArray3[1];
                    break;
                }
            }
            if (dbclient == "mdb")
            {
                if (str[1] != ':')
                {
                    str = Path.Combine(Application.StartupPath, str);
                }
                factory        = new AccessWorkspaceFactoryClass();
                this.Workspace = factory.OpenFromFile(str, 0);
            }
            else if (dbclient == "gdb")
            {
                if (str[1] != ':')
                {
                    str = Path.Combine(Application.StartupPath, str);
                }
                factory        = new FileGDBWorkspaceFactoryClass();
                this.Workspace = factory.OpenFromFile(str, 0);
            }
            else if (dbclient == "sde")
            {
                if (str[1] != ':')
                {
                    str = Path.Combine(Application.StartupPath, str);
                }
                factory        = new SdeWorkspaceFactory();
                this.Workspace = factory.OpenFromFile(str, 0);
            }
            else
            {
                IWorkspaceFactory factory2 = new SdeWorkspaceFactoryClass();
                try
                {
                    IPropertySet connectionProperties = this.CreateConnectionProperty();
                    if (connectionProperties == null)
                    {
                        return;
                    }
                    this.Workspace = factory2.Open(connectionProperties, 0);
                }
                catch (Exception exception)
                {
                    //CErrorLog.writeErrorLog(null, exception, "");
                }
            }

            if (this.Workspace != null)
            {
                this._templateTable = (this.Workspace as IFeatureWorkspace).OpenTable("YT_MAPTEMPLATE");
                this._classTable    = (this.Workspace as IFeatureWorkspace).OpenTable("YT_MAPTEMPLATE_CLASS");
                this._elementTable  = (this.Workspace as IFeatureWorkspace).OpenTable("YT_MAPTEMPLATE_ELEMENT");
                this._paramTable    = (this.Workspace as IFeatureWorkspace).OpenTable("YT_MAPTEMPLATE_PARAM");
                this.ReadClasses();
                this._connectionString = connectionString;
            }
        }
Esempio n. 21
0
        public static IWorkspace GetSDEWorkspace(string connectFile)
        {
            IWorkspaceFactory factory = new SdeWorkspaceFactory();

            return(factory.OpenFromFile(connectFile, 0));
        }
Esempio n. 22
0
        private void TestConn_Click(object sender, EventArgs e)
        {
            Success = false;
            try
            {
                IWorkspace Currworkspace = null;
                string IP = textEdit1.Text;
                string Instance = textEdit2.Text;
                string version = textEdit6.Text;
                string database = textEdit3.Text;
                string user = textEdit7.Text;
                string password = textEdit4.Text;
                string ConnCname = textEdit5.Text;

                IPropertySet propertyset = new ESRI.ArcGIS.esriSystem.PropertySetClass();
                propertyset.SetProperty("Server", IP);
                propertyset.SetProperty("instance", Instance);
                propertyset.SetProperty("database", database);
                propertyset.SetProperty("user", user);
                propertyset.SetProperty("password", password);
                propertyset.SetProperty("version", version);
                IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactory();
                Currworkspace = workspaceFactory.Open(propertyset, 0);
                MessageBox.Show("连接成功!");
                Success = true;

            }
            catch (Exception ex)
            {
                MessageBox.Show("连接失败!");
                Success = false;
                string Error = ex.Message;
            }
        }
Esempio n. 23
0
        public List <string> GetSqlServerTables(string server, string instance, string database, string version, string user = "", string password = "")
        {
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //List<string> Tables = new List<string>();
            //System.Data.DataTable tables;
            //string connString = "Data Source=" + server + "\\" + instance + " ; Initial Catalog=" + database + ";  Trusted_Connection=True; User Id=" + user + "; Password="******"Tables");

            //    for (int i = 0; i < tables.Rows.Count; i++)
            //    {
            //        Tables.Add(tables.Rows[i][2].ToString());
            //    }
            //}
            //catch (Exception ex)
            //{
            //    // Gegebenenfalls Fehlerbehandlung
            //    MessageBox.Show("Error in finding the DB tables for the defined database! " + ex.Message,
            //         "Database Error", MessageBoxButton.OK, MessageBoxImage.Error);
            //}
            //finally
            //{
            //    // Verbindung schließen
            //    conn.Close();
            //}
            //return Tables;
            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //SDE connection
            IPropertySet      pPropSet;
            IWorkspaceFactory pFact;

            pPropSet = new PropertySet();
            pPropSet.SetProperty("dbclient", "SQLServer");
            pPropSet.SetProperty("SERVER", server);
            pPropSet.SetProperty("INSTANCE", instance);
            pPropSet.SetProperty("DATABASE", database);
            pPropSet.SetProperty("VESRSION", version);

            if (user != "" && password != "")
            {
                pPropSet.SetProperty("USER", user);
                pPropSet.SetProperty("PASSWORD", password);
                pPropSet.SetProperty("authentication_mode", "DBMS");
            }
            else
            {
                pPropSet.SetProperty("authentication_mode", "OSA");
            }

            pFact = new SdeWorkspaceFactory();
            List <string> Tables = new List <string>();

            try
            {
                IWorkspace       workspace = pFact.Open(pPropSet, 0);
                IEnumDatasetName eDSNames  = workspace.get_DatasetNames(esriDatasetType.esriDTTable);
                IDatasetName     DSName    = eDSNames.Next();

                //MessageBox.Show(DSName.ToString());
                while (DSName != null)
                {
                    Tables.Add(DSName.Name);
                    DSName = eDSNames.Next();
                }
            }
            catch (Exception ex)
            {
                // Gegebenenfalls Fehlerbehandlung
                MessageBox.Show("Error in finding the DB tables for the defined database! " + ex.Message,
                                "Database Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            Tables.Sort();
            return(Tables);
        }
Esempio n. 24
0
        private static IWorkspace WorkspaceFromSDEFile(string path)
        {
            SdeWorkspaceFactory pWSFactory = new SdeWorkspaceFactory();
            IWorkspace pWSpace = pWSFactory.OpenFromFile(path, 0);

            return pWSpace;
        }
Esempio n. 25
0
        private static IFeatureWorkspace GetWorkspaceFromConnectionOSAuth(string pServer, string pInstance, string pDatabase, string pClient = "sqlserver", string pConnProp = "Rev1.0", bool pIsGeodatabase = true)
        {
            IPropertySet propertySet = new PropertySetClass();
            propertySet.SetProperty("SERVER", pServer);
            propertySet.SetProperty("INSTANCE", pInstance);

            propertySet.SetProperty("DBCLIENT", pClient);
            propertySet.SetProperty("DB_CONNECTION_PROPERTIES", pServer);
            propertySet.SetProperty("IS_GEODATABASE", pIsGeodatabase);
            propertySet.SetProperty("CONNPROP-REV", pConnProp);

            propertySet.SetProperty("DATABASE", pDatabase);
            propertySet.SetProperty("VERSION", "sde.DEFAULT");

            //Operating System Authentication
            propertySet.SetProperty("AUTHENTICATION_MODE", "OSA");

            SdeWorkspaceFactory pWSFactory = new SdeWorkspaceFactory();
            IWorkspace pWSpace = pWSFactory.Open(propertySet, 0);                                                             // GET THE WORKSPACE

            return pWSpace as IFeatureWorkspace;
        }
Esempio n. 26
0
        private IWorkspace Connect(string userName, string password)
        {
            IPropertySet propertySet = null;
            IWorkspaceFactory workspaceFactory = null;

            try
            {
                propertySet = new PropertySet();
                propertySet.SetProperty("SERVER", "");
                propertySet.SetProperty("INSTANCE", "sde:sqlserver:fmiserver");
                propertySet.SetProperty("DATABASE", "sde");
                propertySet.SetProperty("VERSION", "SDE.DEFAULT");
                propertySet.SetProperty("USER", userName);
                propertySet.SetProperty("PASSWORD", password);

                workspaceFactory = new SdeWorkspaceFactory();

                //propertySet = new PropertySet();
                //propertySet.SetProperty("DATABASE", @"C:\Temp\USA.gdb");

                //workspaceFactory = new FileGDBWorkspaceFactoryClass();

                return workspaceFactory.Open(propertySet, IntPtr.Zero.ToInt32());
            }
            finally
            {
                if (workspaceFactory != null)
                    Marshal.ReleaseComObject(workspaceFactory);
                if (propertySet != null)
                    Marshal.ReleaseComObject(propertySet);
            }
        }
Esempio n. 27
0
        public static IWorkspace GetWorkspace()
        {
            IWorkspaceFactory sdeWorkspaceFactoryClass;
            IWorkspace        mPWorkspace;
            Exception         exception;

            if (!AppConfigInfo.m_IsCreate)
            {
                AppConfigInfo.m_IsCreate = true;
                string upper = AppConfigInfo.dbclient.ToUpper();
                if (!(upper == "SQLSERVER" ? false : !(upper == "ORACLE")))
                {
                    sdeWorkspaceFactoryClass = new SdeWorkspaceFactory();
                    try
                    {
                        IPropertySet propertySet = AppConfigInfo.CreateSdePropertySet();
                        if (propertySet != null)
                        {
                            AppConfigInfo.m_pWorkspace = sdeWorkspaceFactoryClass.Open(propertySet, 0);
                        }
                        else
                        {
                            mPWorkspace = null;
                            return(mPWorkspace);
                        }
                    }
                    catch (Exception exception1)
                    {
                        exception = exception1;
                        Logger.Current.Error("", exception, "");
                    }
                }
                else if (upper != "MDB")
                {
                    try
                    {
                        if ((AppConfigInfo.m_LayerConfigDB.Length <= 0
                            ? false
                            : File.Exists(AppConfigInfo.m_LayerConfigDB)))
                        {
                            sdeWorkspaceFactoryClass   = new FileGDBWorkspaceFactory();
                            AppConfigInfo.m_pWorkspace =
                                sdeWorkspaceFactoryClass.OpenFromFile(AppConfigInfo.m_LayerConfigDB, 0);
                        }
                    }
                    catch (Exception exception2)
                    {
                        exception = exception2;
                        MessageBox.Show(exception.Message);
                        Logger.Current.Error("", exception, "");
                    }
                }
                else
                {
                    try
                    {
                        if ((AppConfigInfo.m_LayerConfigDB.Length <= 0
                            ? false
                            : File.Exists(AppConfigInfo.m_LayerConfigDB)))
                        {
                            sdeWorkspaceFactoryClass   = new AccessWorkspaceFactory();
                            AppConfigInfo.m_pWorkspace =
                                sdeWorkspaceFactoryClass.OpenFromFile(AppConfigInfo.m_LayerConfigDB, 0);
                        }
                    }
                    catch (Exception exception3)
                    {
                        exception = exception3;
                        MessageBox.Show(exception.Message);
                        Logger.Current.Error("", exception, "");
                    }
                }
            }
            mPWorkspace = AppConfigInfo.m_pWorkspace;
            return(mPWorkspace);
        }