当前位置: 首页 > 工具软件 > MDB Tools > 使用案例 >

ArcEngine创建MDB、GDB

林昱
2023-12-01
  • 创建MDB
                IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
                if (System.IO.File.Exists(filePath + @"\" + fileName + ".mdb"))
                {
                    MessageBox.Show("该MDB名称已存在,请重新命名");
                    return;
                }
                else
                {
                    IWorkspaceName workspaceName = workspaceFactory.Create(filePath, fileName, null, 0);
                    IWorkspace iwk = workspaceFactory.OpenFromFile(workspaceName.PathName, 0);
                }
  • 创建GDB
                IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass();
                if (System.IO.File.Exists(filePath + @"\" + fileName + ".gdb"))
                {
                    MessageBox.Show("该GDB名称已存在,请重新命名");
                    return;
                }
                else
                {
                    IWorkspaceName workspaceName = workspaceFactory.Create(filePath, fileName, null, 0);
                    IWorkspace iwk = workspaceFactory.OpenFromFile(workspaceName.PathName, 0);
                }
  • 创建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;
            }


     
 类似资料: