创建SQL数据库 ISpatialReference sr = prjControl1.GetSpatialReference();
string server = txtServer.Text;//数据库服务名
string dbname = txtDB.Text;//数据库名
string user = txtUser.Text;//用户名
string pwd = txtPwd.Text;//密码
string LienseFilePath = Application.StartupPath + "\\arcgisservice.ecp";//许可文件
ESRI.ArcGIS.Geoprocessor.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 = server;
cedb.database_name = dbname;
cedb.database_admin = user;
cedb.database_admin_password = pwd;
cedb.sde_schema = "DBO_SCHEMA";
cedb.gdb_admin_name = "";
cedb.gdb_admin_password = "";
cedb.authorization_file = LienseFilePath;
try
{
this.buttonOK.Enabled = this.buttonCancel.Enabled = false;
gp.Execute(cedb as IGPProcess, null);
IWorkspace wk = GetWorkspace(server, user, pwd, dbname);
MessageBox.Show("创建成功!");
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
catch (Exception e2)
{
MessageBox.Show(e2.Message);
}
private IWorkspace GetWorkspace(string server, string user, string pwd, string db)
{
//直连SQL Server数据库
IPropertySet propertySet = new PropertySet();
propertySet.SetProperty("INSTANCE", "sde:sqlserver:" + server);
propertySet.SetProperty("USER", user);
propertySet.SetProperty("PASSWORD", pwd);
propertySet.SetProperty("DATABASE", db);
IWorkspaceFactory sdewf = new SdeWorkspaceFactory();
IWorkspace wk = sdewf.Open(propertySet, 0);
return wk;
}