/// <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;
}