连接SDE数据库
时间:2010-10-16 来源:hl3292
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//ESRI
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesGDB;
// ArcGIS Engine引用
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.ToolbarControl;
using ESRI.ArcGIS.TOCControl;
//using ESRI.ArcGIS.MapControl;
using ESRI.ArcGIS.PageLayoutControl;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.GlobeCore;
using System.Runtime.InteropServices;
/// <summary>
/// 连接sde数据库,并设定map的图层
/// </summary>
private void GetSdeData()
{
/**连接sde数据库**/
//License
IAoInitialize pAoInit = new AoInitializeClass();
pAoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcView);
//Workspace
IWorkspaceFactory pWorkspaceFactory;
pWorkspaceFactory = new SdeWorkspaceFactoryClass();
//PropertySet
IPropertySet pPropertySet;
pPropertySet = new PropertySetClass();
pPropertySet.SetProperty("Service", "esri_sde");
pPropertySet.SetProperty("Server", "192.168.25.110");
//pPropertySet.SetProperties("Database","wjgis");
pPropertySet.SetProperty("Instance", "port:5151");
pPropertySet.SetProperty("user", "sangis");
pPropertySet.SetProperty("password", "sangis");
pPropertySet.SetProperty("version", "sde.DEFAULT");
//IFeatureWorkspace对象
IFeatureWorkspace pSdeWorkspace;
IFeatureDataset pFeatureDataset;
IFeatureClass pFeatureClass;
//图层
IFeatureLayer layer;
try
{
//连接
pSdeWorkspace = (IFeatureWorkspace)pWorkspaceFactory.Open(pPropertySet, 0);
//取数据
pFeatureDataset = pSdeWorkspace.OpenFeatureDataset("buj");
pFeatureClass = pSdeWorkspace.OpenFeatureClass("TV井盖");
//定义图层
layer = new FeatureLayerClass();
//设定layer的FeatureClass属性
layer.FeatureClass = pFeatureClass;
//设定Map的图层
MapControl.Map.AddLayer(layer);
}
catch (Exception ex)
{
MessageBox.Show("SDE数据库不能连接!" ex.Message);
//text_sqlfilter.Text = ex.Message;
}
}