ArcEngine10.1直连Oracle



好久没写AE的东西了,好多东西都忘记了,这里记录一下直连Oracle,注意instance的拼接。

/// 
        /// 连接Oracle数据库SDE
        /// 
        /// 连接IP
        /// 数据库实例名orcl
        /// 用户名
        /// 密码
        /// 
        public IWorkspace Con2OracleSDE(string sAddress, string sInstance, string sUser, string sPassword)
        {
            IWorkspaceFactory pSdeWksFactory = new SdeWorkspaceFactory();
            IWorkspace pWorkspace = null;
            try
            {
                IPropertySet propSet = new PropertySetClass();
                propSet.SetProperty("server", sAddress);
                //propSet.SetProperty("instance", "sde:oracle11g:" + sAddress + @"/" + sDBName);
                //propSet.SetProperty("instance", "sde:oracle11g:" + sDBName);
                propSet.SetProperty("instance", "sde:oracle11g$//" + sAddress + "/" + sInstance);               
                propSet.SetProperty("user", sUser);
                propSet.SetProperty("password", sPassword);
                propSet.SetProperty("version", "SDE.DEFAULT");

                pWorkspace = pSdeWksFactory.Open(propSet, 0);
                return pWorkspace;
            }
            catch (Exception ex)
            {
                return null;
            }
        }


另外也可以通过ArcCatalog中配置的数据库连接(.sde文件)进行数据库连接。