• C#+ArcEngine创建企业数据库、连接及相关


    /// <summary>
    /// 创建SQLServer企业数据库(数据库拥有者:DBO)
    /// </summary>
    public string CreateEnterpriseDB(string sInstance, string sDBName, string sUser, string sPassword, string LienseFilePath)
    {

    Geoprocessor gp = new Geoprocessor();
    gp.OverwriteOutput = true;

    ESRI.ArcGIS.DataManagementTools.CreateEnterpriseGeodatabase cedb = new ESRI.ArcGIS.DataManagementTools.CreateEnterpriseGeodatabase();

    cedb.database_platform = "SQL_Server";
    cedb.instance_name = sInstance;
    cedb.database_name = sDBName;
    cedb.database_admin = sUser;
    cedb.database_admin_password = sPassword;
    cedb.sde_schema = "DBO_SCHEMA";
    cedb.gdb_admin_name = "";
    cedb.gdb_admin_password = "";

    cedb.authorization_file = LienseFilePath.ToString();//授权文件,本例用的是ArcGIS 10.2的授权文件
    try
    {
    gp.Execute(cedb, null);
    }
    catch
    {
    string str = "";
    for (int i = 0; i < gp.MessageCount; i++)
    {
    str += gp.GetMessage(i);
    str += " ";
    }
    return str;
    }
    return null;
    }

    /// <summary>
    /// 创建SQLServer数据库连接
    /// </summary>
    /// <param name="sInstance">地址</param>
    /// <param name="sDBName">数据库名</param>
    /// <param name="sUserName">用户名</param>
    /// <param name="sPassword">密码</param>
    public string CreateSqlConnection(string sInstance, string sDBName, string sUserName, string sPassword, string SdeFilePath)
    {

    Geoprocessor gp = new Geoprocessor();
    gp.OverwriteOutput = true; //覆盖原有文件并重写
    ESRI.ArcGIS.DataManagementTools.CreateDatabaseConnection CreateDBConnection = new ESRI.ArcGIS.DataManagementTools.CreateDatabaseConnection();
    //设置sde默认文件夹路径
    CreateDBConnection.out_folder_path = SdeFilePath;
    //数据库连接文件的名称
    CreateDBConnection.out_name = "ConnectionTo" + sDBName.ToString();
    //数据库连接平台
    CreateDBConnection.database_platform = "SQL_SERVER";
    //数据库连接实例:本机的IP地址或计算机名
    CreateDBConnection.instance = sInstance;
    //连接的数据库用户名"sa"
    CreateDBConnection.username = sUserName;
    //连接的数据库密码"123@abcd"
    CreateDBConnection.password = sPassword;
    //此数据库为SQL Server 中已经存在的数据库(不是空间库)
    CreateDBConnection.database = sDBName;
    CreateDBConnection.version_type = "TRANSACTIONAL";
    CreateDBConnection.account_authentication = "DATABASE_AUTH";
    try
    {
    gp.Execute(CreateDBConnection, null);
    }
    catch (Exception E)
    {
    string str = "";
    for (int i = 0; i < gp.MessageCount; i++)
    {
    str += gp.GetMessage(i);
    str += " ";
    }
    return str;

    }
    return null;

    }

    /// <summary>
    /// 创建ORCL数据库连接
    /// </summary>
    /// <param name="sDBName"></param>
    /// <param name="sUserName"></param>
    /// <param name="sPassword"></param>
    /// <param name="SdeFilePath"></param>
    /// <returns></returns>
    public string CreateOrclConnection(string sDBName, string sUserName, string sPassword, string SdeFilePath)
    {
    Geoprocessor GP = new Geoprocessor();
    GP.OverwriteOutput = true; //覆盖原有文件并重写

    //创建数据库连接文件(.sde)
    ESRI.ArcGIS.DataManagementTools.CreateDatabaseConnection createdbconnection = new ESRI.ArcGIS.DataManagementTools.CreateDatabaseConnection();
    //设置sde默认文件夹路径
    createdbconnection.out_folder_path = SdeFilePath;
    //数据库连接文件的名称
    createdbconnection.out_name = "ConnectionTo" + sDBName.ToString();
    //数据库连接平台
    createdbconnection.database_platform = "ORACLE";
    //数据库连接实例
    createdbconnection.instance = sDBName;
    //连接的数据库用户名
    createdbconnection.username = sUserName;
    //连接的数据库密码
    createdbconnection.password = sPassword;

    try
    {
    GP.Execute(createdbconnection, null);

    }
    catch (Exception E)
    {
    string str = "";
    for (int i = 0; i < GP.MessageCount; i++)
    {
    str += GP.GetMessage(i);
    str += " ";

    }
    return str;
    }

    return null;
    }

    /// <summary>
    /// 数据库转空间库
    /// </summary>
    public string ConvertDB2GeoDB(string sInstance, string SdeFilePath, string LienseFilePath)
    {
    //sde文件的全名
    string SdeConnFilePathName = SdeFilePath + @"ConnectionTo" + sInstance + ".sde";

    Geoprocessor gp = new Geoprocessor();
    gp.OverwriteOutput = true;
    ESRI.ArcGIS.DataManagementTools.EnableEnterpriseGeodatabase enabledb = new ESRI.ArcGIS.DataManagementTools.EnableEnterpriseGeodatabase();

    //使用上一步创建好的数据库连接文件
    enabledb.input_database = SdeConnFilePathName;
    enabledb.authorization_file = LienseFilePath.ToString();
    try
    {
    gp.Execute(enabledb, null);
    }
    catch (Exception e)
    {
    string str = "";
    for (int i = 0; i < gp.MessageCount; i++)
    {
    str += gp.GetMessage(i);
    str += " ";
    }
    return str;
    }
    return null;
    }

  • 相关阅读:
    【spring cloud】spring cloud zuul 路由网关
    【IDEA】【maven】idea使用maven插件 打包提示找不到符号找不到类,但是却没有错误
    【java】关于Map的排序性的一次使用,有序的Map
    【idea】idea重新打包依赖了父级项目的子级项目,父级项目代码改变,但是子级项目打包依旧是老的代码 问题解决
    【mysql】在mysql中更新字段的部分值,更新某个字符串字段的部分内容
    CentOS RabbitMQ 高可用(Mirrored)
    CentOS MongoDB 高可用实战
    CentOS 安装 gitlab
    SpringBoot打jar包问题
    java中由类名和方法名字符串实现其调用【反射机制】
  • 原文地址:https://www.cnblogs.com/khfang/p/5783158.html
Copyright © 2020-2023  润新知