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; } }
/// <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); } }
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)); }
/// <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; }
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); }
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); }
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; }
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); }
/// <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); } }
/// <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)); }
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空间数据库成功"); }
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); }
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); }
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); }
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; } }
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); }
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; }
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); }
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); } }
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(); } }