ArcSDE:C#打开SDE数据库的几种方式总结

转自原文 ArcSDE:C#打开SDE数据库的几种方式总结

 

1.通过指定连接属性参数打开数据库

 

  1. /// <param name="server">数据库服务器名</param>  
  2. /// <param name="instance">SDE的端口,默认安装时"port:5151"</param>  
  3. /// <param name="user">SDE的用户名</param>  
  4. /// <param name="password">密码</param>  
  5. /// <param name="database">数据库的名字</param>  
  6. /// <param name="version">SDE的版本</param>  
  7. /// <returns></returns>  
  8. public IWorkspace OpenSdeWorkspaceByPropertySet(string server, string instance, string user, string password, string database, string version)  
  9. {  
  10.     IPropertySet Propset = new PropertySetClass();  
  11.     Propset.SetProperty("SERVER", server);  
  12.     Propset.SetProperty("INSTANCE", instance);  
  13.     Propset.SetProperty("USER", user);  
  14.     Propset.SetProperty("PASSWORD", password);  
  15.     Propset.SetProperty("DATABASE", password);  
  16.     Propset.SetProperty("VERSION", version);  
  17.   
  18.     IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass();  
  19.     return workspaceFactory.Open(Propset, 0);  
  20. }  

2.通过连接字符串打开数据库

 

  1. /// <param name="connectionString">连接字符串</param>  
  2. /// For example, "SERVER=Kona;DATABASE=sde;INSTANCE=5151;USER=Editor;PASSWORD=Editor;VERSION=sde.DEFAULT"  
  3. /// <returns></returns>  
  4. public IWorkspace OpenSdeWorkspaceByConnectionString(string connectionString)  
  5. {  
  6.     IWorkspaceFactory2 workspaceFactory = new SdeWorkspaceFactoryClass();  
  7.     return workspaceFactory.OpenFromString(connectionString, 0);  
  8. }  

3.通过sde文件打开数据库

 

    1. /// <param name="connectionFile">sde文件</param>  
    2. /// For example, "C:\\Data.sde"  
    3. /// <returns></returns>  
    4. public IWorkspace OpenSdeWorkspaceFromFile(string connectionFile)  
    5. {  
    6.     IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass();  
    7.     return workspaceFactory.OpenFromFile(connectionFile, 0);  
    8.  

 

posted @ 2017-01-19 09:14  wenglabs  阅读(1268)  评论(0编辑  收藏  举报