转自原文
1.通过指定连接属性参数打开
/// 数据库服务器名 /// SDE的端口,默认安装时"port:5151" /// SDE的用户名 /// 密码 /// 数据库的名字 /// SDE的版本 ///public IWorkspace OpenSdeWorkspaceByPropertySet(string server, string instance, string user, string password, string database, string version) { IPropertySet Propset = new PropertySetClass(); Propset.SetProperty("SERVER", server); Propset.SetProperty("INSTANCE", instance); Propset.SetProperty("USER", user); Propset.SetProperty("PASSWORD", password); Propset.SetProperty("DATABASE", password); Propset.SetProperty("VERSION", version); IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass(); return workspaceFactory.Open(Propset, 0); }
2.通过连接字符串打开数据库
/// 连接字符串 /// For example, "SERVER=Kona;DATABASE=sde;INSTANCE=5151;USER=Editor;PASSWORD=Editor;VERSION=sde.DEFAULT" ///public IWorkspace OpenSdeWorkspaceByConnectionString(string connectionString) { IWorkspaceFactory2 workspaceFactory = new SdeWorkspaceFactoryClass(); return workspaceFactory.OpenFromString(connectionString, 0); }
3.通过sde文件打开数据库
/// sde文件 /// For example, "C:\\Data.sde" ///public IWorkspace OpenSdeWorkspaceFromFile(string connectionFile) { IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass(); return workspaceFactory.OpenFromFile(connectionFile, 0); }