标签:
1.通过指定连接属性参数打开数据库
public IPropertySet ConnectSdeSQL(string sAddress, string sDBName, string sUser, string sPassword)
{
IPropertySet propSet = new PropertySetClass();
propSet.SetProperty("SERVER", sAddress);//服务器地址,如:192.168.34.152
propSet.SetProperty("INSTANCE", "sde:sqlserver:" + sAddress + "");//连接实例,如sde:sqlserver:192.168.34.152
propSet.SetProperty("DATABASE", sDBName);//要连接的数据库名称
propSet.SetProperty("USER", sUser);//用户名
propSet.SetProperty("PASSWORD", sPassword);密码
propSet.SetProperty("VERSION", "DBO.DEFAULT");//数据库的拥有者也就是数据库的架构,一般是DBO或SDE
propSet.SetProperty("AUTHENTICATION_MODE", "DBMS");
return propSet;
}
2.通过连接字符串打开数据库
public IWorkspace OpenSdeWorkspaceByConnectionString(string connectionString)
{
IWorkspaceFactory2 workspaceFactory = new SdeWorkspaceFactoryClass();
return workspaceFactory.OpenFromString(connectionString, 0);
}
3.通过sde文件打开数据库
public IWorkspace OpenSdeWorkspaceFromFile(string connectionFile)
{
IWorkspaceFactory workspaceFactory = new SdeWorkspaceFactoryClass();
return workspaceFactory.OpenFromFile(connectionFile, 0);
}
标签:
原文地址:http://www.cnblogs.com/khfang/p/5787395.html