示例#1
0
        private void button9_Click(object sender, EventArgs e)
        {
            string text = "";
            string str  = "";
            string str1 = "";
            string str2 = "";
            string str3 = "";

            text = this.MachineName.Text;
            str  = this.SQLUserName.Text.Trim();
            str1 = this.SQLUserPwd.Text.Trim();
            str3 = this.newLogin.Text.Trim();
            str2 = (!this.radioButton3.Checked ? this.textBox5.Text.Trim() : this.textBox2.Text.Trim());
            if (text == "")
            {
                MessageBox.Show("主机名不能为空");
            }
            else if (!(str == null ? false : !(str == "")))
            {
                MessageBox.Show("登录用户名不能为空!");
            }
            else if (!(str2 == null ? false : !(str2 == "")))
            {
                MessageBox.Show("数据库的名称不能为空!");
            }
            else if ((str3 == null ? false : !(str3 == "")))
            {
                string[] strArrays = new string[]
                {
                    "Provider=SQLOLEDB;Data Source=", text, ";Initial Catalog=", str2, ";User Id=", str, ";Password="******"BEGIN exec  sp_revokedbaccess N'", str3, "'  exec sp_droplogin N'", str3, "' END " };
                        string str4 = string.Concat(strArrays);
                        oleDbDataAccessLayer.ExecuteNonQuery(str4, new object[0]);
                        MessageBox.Show("删除访问数据库用户成功!");
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message.ToString());
                        return;
                    }
                }
                finally
                {
                    oleDbDataAccessLayer.Close();
                }
            }
            else
            {
                MessageBox.Show("被删除的用户名不能为空!");
            }
        }
示例#2
0
        private void button5_Click(object sender, EventArgs e)
        {
            string[]             strArrays;
            string               str;
            OleDbDataAccessLayer oleDbDataAccessLayer;
            string               text    = "";
            string               str1    = "";
            string               str2    = "";
            string               str3    = "";
            string               str4    = "";
            string               str5    = "";
            string               sQLHome = "";

            if (!this.radioButton3.Checked)
            {
                text = this.MachineName.Text.Trim();
                str1 = this.SQLUserName.Text.Trim();
                str2 = this.SQLUserPwd.Text.Trim();
                str3 = this.textBox5.Text.Trim();
                str4 = this.textBox4.Text.Trim();
                str5 = this.textBox3.Text.Trim();
                if (!(text == null ? false : !(text == "")))
                {
                    MessageBox.Show("主机名不能为空");
                }
                else if (!(str1 == null ? false : !(str1 == "")))
                {
                    MessageBox.Show("登录用户名不能为空!");
                }
                else if (!(str3 == null ? false : !(str3 == "")))
                {
                    MessageBox.Show("附加数据库的名称不能为空!");
                }
                else if (!(str4 == null ? false : !(str4 == "")))
                {
                    MessageBox.Show("数据库附加的路径不能为空!");
                }
                else if (!(str5 == null ? false : !(str5 == "")))
                {
                    MessageBox.Show("数据库附加日志文件的路径不能为空!");
                }
                else if (
                    !(str4.Substring(str4.Length - 1, 1) == "\\"
                        ? false
                        : !(str4.Substring(str4.Length - 4, 4).ToLower() != ".mdf")))
                {
                    MessageBox.Show("必须输入完整并且正确的备份文件名!");
                }
                else if ((str5.Substring(str5.Length - 1, 1) == "\\"
                    ? false
                    : !(str5.Substring(str5.Length - 4, 4).ToLower() != ".ldf")))
                {
                    strArrays = new string[] { "server=", text, ";User Id=", str1, ";Password="******"你确认进行数据库附加吗?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
                        System.Windows.Forms.DialogResult.Yes)
                    {
                        if (!this.method_0(str, str3, str4, str5))
                        {
                            MessageBox.Show("数据库附加失败!");
                        }
                        else
                        {
                            MessageBox.Show("数据库附加成功!");
                            if (str3.Trim().ToUpper() == "SDE")
                            {
                                strArrays = new string[]
                                {
                                    "Provider=SQLOLEDB;Data Source=", text, ";Initial Catalog='master';User Id=", str1,
                                    ";Password="******"BEGIN exec sp_addlogin  'sde','go','sde' END ", new object[0]);
                                        MessageBox.Show("恢复SDE数据库添加SDE登录用户成功!");
                                    }
                                    catch (Exception exception)
                                    {
                                    }
                                }
                                finally
                                {
                                    oleDbDataAccessLayer.Close();
                                }
                                strArrays = new string[]
                                {
                                    "Provider=SQLOLEDB;Data Source=", text, ";Initial Catalog='sde';User Id=", str1,
                                    ";Password="******"BEGIN exec sp_change_users_login 'update_one','sde','sde'  END ",
                                            new object[0]);
                                        MessageBox.Show("恢复SDE数据库以后解决SID不一致问题成功!");
                                    }
                                    catch (Exception exception1)
                                    {
                                    }
                                }
                                finally
                                {
                                    oleDbDataAccessLayer.Close();
                                }
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("必须输入完整并且正确的备份文件名!");
                }
            }
            else
            {
                text = this.MachineName.Text;
                str1 = this.SQLUserName.Text.Trim();
                str2 = this.SQLUserPwd.Text.Trim();
                str3 = this.textBox2.Text.Trim();
                str4 = this.textBox1.Text.Trim();
                this.SQLBakName.Text.Trim();
                this.SQLBakDescript.Text.Trim();
                sQLHome = SQlDBManage.getSQLHome();
                if (!this.checkBox1.Checked)
                {
                    sQLHome = this.SQLDataFilePath.Text.Trim();
                }
                this.sqlDBManage_0.ServerName = this.MachineName.Text;
                this.sqlDBManage_0.UserName   = this.SQLUserName.Text.Trim();
                this.sqlDBManage_0.Password   = this.SQLUserPwd.Text.Trim();
                if (text == "")
                {
                    MessageBox.Show("主机名不能为空");
                }
                else if (!(str1 == null ? false : !(str1 == "")))
                {
                    MessageBox.Show("登录用户名不能为空!");
                }
                else if (!(str3 == null ? false : !(str3 == "")))
                {
                    MessageBox.Show("还原数据库的名称不能为空!");
                }
                else if (!(str4 == null || str4 == "" ? false : !this.sqlDBManage_0.hasBlack(str4)))
                {
                    MessageBox.Show("要还原数据库备份文件的路径不能为空或含有空格!");
                }
                else if (!(str4 == null ? false : !(str4 == "")))
                {
                    MessageBox.Show("要还原数据库备份文件的路径不能为空!");
                }
                else if ((str4.Substring(str4.Length - 1, 1) == "\\"
                    ? false
                    : !(str4.Substring(str4.Length - 4, 4).ToLower() != ".bak")))
                {
                    if (!this.checkBox1.Checked)
                    {
                        if ((sQLHome == null || sQLHome == "" ? false : !this.sqlDBManage_0.hasBlack(sQLHome)))
                        {
                            goto Label1;
                        }
                        MessageBox.Show("数据存放路径不能为空或含有空格!");
                        return;
                    }
Label1:
                    if (MessageBox.Show("你确认进行数据库恢复吗?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
                        System.Windows.Forms.DialogResult.Yes)
                    {
                        this.progressBar2.Visible = true;
                        if (!this.sqlDBManage_0.RestoreDB(str3, str4, sQLHome, this.progressBar2))
                        {
                            MessageBox.Show("数据库恢复失败!");
                            this.progressBar2.Visible = false;
                        }
                        else
                        {
                            MessageBox.Show("数据库恢复成功!");
                            this.progressBar2.Visible = false;
                            if (str3.Trim().ToUpper() == "SDE")
                            {
                                strArrays = new string[]
                                {
                                    "Provider=SQLOLEDB;Data Source=", text, ";Initial Catalog='master';User Id=", str1,
                                    ";Password="******"BEGIN exec sp_addlogin  'sde','go','sde' END ", new object[0]);
                                        MessageBox.Show("恢复SDE数据库添加SDE登录用户成功!");
                                    }
                                    catch (Exception exception2)
                                    {
                                    }
                                }
                                finally
                                {
                                    oleDbDataAccessLayer.Close();
                                }
                                strArrays = new string[]
                                {
                                    "Provider=SQLOLEDB;Data Source=", text, ";Initial Catalog='sde';User Id=", str1,
                                    ";Password="******"BEGIN exec sp_change_users_login 'update_one','sde','sde'  END ",
                                            new object[0]);
                                        MessageBox.Show("恢复SDE数据库以后解决SID不一致问题成功!");
                                    }
                                    catch (Exception exception3)
                                    {
                                    }
                                }
                                finally
                                {
                                    oleDbDataAccessLayer.Close();
                                }
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("必须输入完整并且正确的备份文件名!");
                }
            }
        }
示例#3
0
        private void bAddUser_Click(object sender, EventArgs e)
        {
            string text  = "";
            string str   = "";
            string str1  = "";
            string text1 = "";
            string str2  = "";
            string text2 = "";

            text  = this.MachineName.Text;
            str   = this.SQLUserName.Text.Trim();
            str1  = this.SQLUserPwd.Text.Trim();
            str2  = this.newLogin.Text.Trim();
            text2 = this.newPwd.Text;
            text1 = this.SQLSDE.Text;
            if (text == "")
            {
                MessageBox.Show("主机名不能为空");
            }
            else if (!(str == null ? false : !(str == "")))
            {
                MessageBox.Show("登录用户名不能为空!");
            }
            else if (!(text1 == null ? false : !(text1 == "")))
            {
                MessageBox.Show("要新建用户的数据库名称不能为空!");
            }
            else if ((str2 == null ? false : !(str2 == "")))
            {
                string[] strArrays = new string[]
                {
                    "Provider=SQLOLEDB;Data Source=", text, ";Initial Catalog=", text1, ";User Id=", str, ";Password="******"BEGIN exec sp_addlogin N'", str2, "', '", text2, "', N'", text1,
                            "', N'简体中文'  EXEC sp_grantdbaccess N'", str2, "', N'", str2, "'  END "
                        };
                        string str3 = string.Concat(strArrays);
                        oleDbDataAccessLayer.ExecuteNonQuery(str3, new object[0]);
                        if (this.checkBox2.Checked)
                        {
                            string str4 = string.Concat("BEGIN EXEC sp_addrolemember 'db_owner','", str2, "' END");
                            oleDbDataAccessLayer.ExecuteNonQuery(str4, new object[0]);
                        }
                        MessageBox.Show("新增访问数据库用户成功!");
                    }
                    catch (Exception exception)
                    {
                        exception.Message.ToString();
                        MessageBox.Show("新增访问数据库用户失败!");
                        return;
                    }
                }
                finally
                {
                    oleDbDataAccessLayer.Close();
                }
            }
            else
            {
                MessageBox.Show("新建用户名不能为空");
            }
        }