Esempio n. 1
0
        // 获得 SQL Server 信息
        // return:
        //      -1  出错
        //      0   放弃
        //      1   成功
        public int GetSqlServerInfo(
            string strSqlServerName,
            out SqlServerInfo info,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            info = new SqlServerInfo();

            REDO_INPUT:
            SaLoginDialog dlg = new SaLoginDialog();
            GuiUtil.AutoSetDefaultFont(dlg);
            dlg.SqlServerName = strSqlServerName;
            dlg.StartPosition = FormStartPosition.CenterScreen;

            dlg.ShowDialog(this);

            if (dlg.DialogResult != DialogResult.OK)
                return 0;

            info.ServerName = strSqlServerName;
            info.SqlUserName = dlg.SqlUserName;
            info.SqlUserPassword = dlg.SqlPassword;
            info.SSPI = dlg.SSPI;

            string strConnection = @"Persist Security Info=False;"
                + "User ID=" + info.SqlUserName + ";"    //帐户和密码
                + "Password="******";"
                + "Data Source=" + strSqlServerName + ";"
                + "Connect Timeout=30";

            if (info.SSPI == true)
            {
                strConnection = @"Persist Security Info=False;"
                    + "Integrated Security=SSPI; "      //信任连接
                    + "Data Source=" + strSqlServerName + ";"
                    + "Connect Timeout=30"; // 30秒
            }

            SqlConnection connection = null;
            try
            {
                connection = new SqlConnection(strConnection);
            }
            catch (Exception ex)
            {
                strError = "建立连接时出错:" + ex.Message + " 类型:" + ex.GetType().ToString();
                return -1;
            }

            try
            {
                connection.Open();
            }
            catch (SqlException sqlEx)
            {
                strError = "连接SQL服务器出错:" + sqlEx.Message + "。";
                int nError = sqlEx.ErrorCode;
                MessageBox.Show(this, strError);
                goto REDO_INPUT;
                return -1;
            }
            catch (Exception ex)
            {
                strError = "连接SQL服务器出错:" + ex.Message + " 类型:" + ex.GetType().ToString();
                return -1;
            }

            /* http://support.microsoft.com/kb/321185
             * 10 -- SQL Server 2008
             * 9 -- SQL Server 2005
             * 8 -- SQL 2000
             * 7 -- SQL 7.0
             * */

            try
            {
                string strVersion = "7";
                string strCommand = "";
                SqlCommand command = null;

                // Debug.Assert(false, "");

                strCommand = "SELECT SERVERPROPERTY('productversion')";
                command = new SqlCommand(strCommand,
                    connection);
                try
                {
                    strVersion = (string)command.ExecuteScalar();
                    // 去掉次要版本号
                    nRet = strVersion.IndexOf(".");
                    if (nRet != -1)
                        strVersion = strVersion.Substring(0, nRet);
                }
                catch (Exception /*ex*/)
                {
                    // strError = "执行命令 " + strCommand + " 出错:" + ex.Message + " 类型:" + ex.GetType().ToString();
                    // return -1;
                    strVersion = "7";
                }

                info.Version = strVersion;

                strCommand = "SELECT SERVERPROPERTY('IsIntegratedSecurityOnly')";
                command = new SqlCommand(strCommand,
                    connection);
                try
                {
                    nRet = (Int32)command.ExecuteScalar();
                }
                catch (Exception ex)
                {
                    //strError = "执行命令 " + strCommand + " 出错:" + ex.Message + " 类型:" + ex.GetType().ToString();
                    //return -1;
                    nRet = 1;
                }

                if (nRet == 1)
                    info.IntegratedSecurityOnlyMode = true;
                else
                    info.IntegratedSecurityOnlyMode = false;

            }
            finally
            {
                connection.Close();
            }

            return 0;
        }
Esempio n. 2
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            if (this.textBox_sqlServerName.Text == "")
            {
                strError = "尚未指定 SQL 服务器";
                goto ERROR1;
            }

            if (string.Compare(this.textBox_sqlServerName.Text.Trim(), "~sqlite") == 0)
            {
                strError = "MS SQL 服务器名不能为 '~sqlite',因为这个名字保留给了 SQLite 内置数据库类型";
                goto ERROR1;
            }

#if NO
                    // 获得 SQL Server 信息
            SqlServerInfo info = null;
            nRet = GetSqlServerInfo(
        this.SqlServerName,
        dlg.SqlUserName,
        dlg.SqlPassword,
        dlg.SSPI,
            out info,
            out strError);
            if (nRet == -1)
                goto ERROR1;
#endif

            nRet = GetIntegratedSecurityOnlyMode(this.textBox_sqlServerName.Text, out strError);
            if (nRet == -1)
                MessageBox.Show(this, strError);

            bool bISOM = false;
            if (nRet == 1)
                bISOM = true;

            // 集成权限登录唯一方式的情况下,不要创建 登录名
            if (bISOM == true)
            {
                this.textBox_loginName.Text = "";
                this.textBox_loginPassword.Text = "";
                this.textBox_confirmLoginPassword.Text = "";
            }
            else
            {
                if (this.textBox_loginName.Text == "")
                {
                    strError = "尚未指定 dp2Kernel 登录名";
                    goto ERROR1;
                }

                if (this.textBox_loginPassword.Text != this.textBox_confirmLoginPassword.Text)
                {
                    strError = "dp2Kernel 登录名的密码和确认密码不一致";
                    goto ERROR1;
                }
            }

            /*
            if (this.SSPI == false && this.textBox_sqlUserName.Text == "")
            {
                MessageBox.Show(this, "尚未指定SQL帐号。");
                return;
            }


            // 检测SQL帐户是否正确
            EnableControls(false);
            string strError = "";
            int nRet = this.detect(this.textBox_sqlServerName.Text,
                this.textBox_sqlUserName.Text,
                this.textBox_sqlPassword.Text,
                radioButton_SSPI.Checked,
                out strError);
            EnableControls(true);
            if (nRet == -1)
            {
                strError = strError + "\r\n" + "请重新指定服务器信息。";
                MessageBox.Show(this, strError);
                return;
            }
             * */

            SaLoginDialog dlg = new SaLoginDialog();
            GuiUtil.AutoSetDefaultFont(dlg);
            dlg.SqlServerName = this.textBox_sqlServerName.Text;
            dlg.StartPosition = FormStartPosition.CenterScreen;

            dlg.ShowDialog(this);

            if (dlg.DialogResult != DialogResult.OK)
                return;

            if (string.IsNullOrEmpty(this.textBox_loginName.Text) == false)
            {
                // 创建dp2Kernel登录名

                // 创建一个适合于dpKernel的SQL Server login
                // return:
                //      -1  出错
                //      0   成功
                //      1   原来已经存在,且不允许删除
                nRet = CreateLogin(
                    this.SqlServerName,
                    dlg.SqlUserName,
                    dlg.SqlPassword,
                    dlg.SSPI,
                    this.textBox_loginName.Text,
                    this.textBox_loginPassword.Text,
                    out strError);
                if (nRet == -1 || nRet == 1)
                {
                    goto ERROR1;
                }
            }

            if (bISOM == true)
            {
                nRet = AddSystemDbCreatorRole(
        this.SqlServerName,
        dlg.SqlUserName,
        dlg.SqlPassword,
        dlg.SSPI,
        out strError);
                if (nRet == -1)
                {
                    strError = "为 登录名 'NT AUTHORITY\\SYSTEM' 添加 'dbcreator' 时出错: " + strError;
                    goto ERROR1;
                }
            }

            /*
            if (nRet == 1)
            {
                string strText = "登录名 '" + this.textBox_loginName.Text + "' 在SQL服务器 '" + this.SqlServerName + "' 中已经存在,但其密码不一定和当前指定的密码相同。\r\n\r\n是否继续使用这个登录名?\r\n(Yes)继续使用;(No)重新指定登录名和密码";
                DialogResult result = MessageBox.Show(this,
                    strText,
                    "setup_dp2Kernel",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question,
                    MessageBoxDefaultButton.Button2);
                if (result == DialogResult.No)
                {
                    this.textBox_loginPassword.Focus();
                    return;
                }
            }
             * */

            this.DialogResult = DialogResult.OK;
            this.Close();
            return;
        ERROR1:
            MessageBox.Show(this, strError);
            MessageBox.Show(this, "虽然刚才的创建登录名操作失败了,但您也可以在重新指定登录名和密码后,再次按“确定”按钮创建登录名,继续进行安装");
        }
Esempio n. 3
0
        // 获得 SQL Server 信息
        // return:
        //      -1  出错
        //      0   放弃
        //      1   成功
        int GetSqlServerInfo(
            string strSqlServerName,
            out MsSqlServerInfo info,
            out string strError)
        {
            strError = "";
            int nRet = 0;

            info = new MsSqlServerInfo();

REDO_INPUT:
            SaLoginDialog dlg = new SaLoginDialog();

            GuiUtil.AutoSetDefaultFont(dlg);
            dlg.SqlServerName = strSqlServerName;
            dlg.StartPosition = FormStartPosition.CenterScreen;

            dlg.ShowDialog(this);

            if (dlg.DialogResult != DialogResult.OK)
            {
                return(0);
            }

            info.ServerName      = strSqlServerName;
            info.SqlUserName     = dlg.SqlUserName;
            info.SqlUserPassword = dlg.SqlPassword;
            info.SSPI            = dlg.SSPI;

            string strConnection = @"Persist Security Info=False;"
                                   + "User ID=" + info.SqlUserName + ";" //帐户和密码
                                   + "Password="******";"
                                   + "Data Source=" + strSqlServerName + ";"
                                   + "Connect Timeout=30";

            if (info.SSPI == true)
            {
                strConnection = @"Persist Security Info=False;"
                                + "Integrated Security=SSPI; " //信任连接
                                + "Data Source=" + strSqlServerName + ";"
                                + "Connect Timeout=30";        // 30秒
            }

            SqlConnection connection = null;

            try
            {
                connection = new SqlConnection(strConnection);
            }
            catch (Exception ex)
            {
                strError = "建立连接时出错:" + ex.Message + " 类型:" + ex.GetType().ToString();
                return(-1);
            }

            try
            {
                connection.Open();
            }
            catch (SqlException sqlEx)
            {
                strError = "连接SQL服务器出错:" + sqlEx.Message + "。";
                int nError = sqlEx.ErrorCode;
                MessageBox.Show(this, strError);
                goto REDO_INPUT;
                return(-1);
            }
            catch (Exception ex)
            {
                strError = "连接SQL服务器出错:" + ex.Message + " 类型:" + ex.GetType().ToString();
                return(-1);
            }

            /* http://support.microsoft.com/kb/321185
             * 10 -- SQL Server 2008
             * 9 -- SQL Server 2005
             * 8 -- SQL 2000
             * 7 -- SQL 7.0
             * */

            try
            {
                string     strVersion = "7";
                string     strCommand = "";
                SqlCommand command    = null;

                // Debug.Assert(false, "");

                strCommand = "SELECT SERVERPROPERTY('productversion')";
                command    = new SqlCommand(strCommand,
                                            connection);
                try
                {
                    strVersion = (string)command.ExecuteScalar();
                    // 去掉次要版本号
                    nRet = strVersion.IndexOf(".");
                    if (nRet != -1)
                    {
                        strVersion = strVersion.Substring(0, nRet);
                    }
                }
                catch (Exception /*ex*/)
                {
                    // strError = "执行命令 " + strCommand + " 出错:" + ex.Message + " 类型:" + ex.GetType().ToString();
                    // return -1;
                    strVersion = "7";
                }

                info.Version = strVersion;

                strCommand = "SELECT SERVERPROPERTY('IsIntegratedSecurityOnly')";
                command    = new SqlCommand(strCommand,
                                            connection);
                try
                {
                    nRet = (Int32)command.ExecuteScalar();
                }
                catch (Exception ex)
                {
                    //strError = "执行命令 " + strCommand + " 出错:" + ex.Message + " 类型:" + ex.GetType().ToString();
                    //return -1;
                    nRet = 1;
                }

                if (nRet == 1)
                {
                    info.IntegratedSecurityOnlyMode = true;
                }
                else
                {
                    info.IntegratedSecurityOnlyMode = false;
                }
            }
            finally
            {
                connection.Close();
            }

            return(1);
        }
Esempio n. 4
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            string strError = "";
            int    nRet     = 0;

            if (this.textBox_sqlServerName.Text == "")
            {
                strError = "尚未指定 MySQL 服务器";
                goto ERROR1;
            }

            if (string.Compare(this.textBox_sqlServerName.Text.Trim(), "~sqlite") == 0)
            {
                strError = "MySQL 服务器名不能为 '~sqlite',因为这个名字保留给了 SQLite 内置数据库类型";
                goto ERROR1;
            }

            if (this.textBox_loginName.Text == "")
            {
                strError = "尚未指定 MySQL 用户名";
                goto ERROR1;
            }

            if (this.textBox_loginPassword.Text != this.textBox_confirmLoginPassword.Text)
            {
                strError = "MySQL 帐户的密码和确认密码不一致";
                goto ERROR1;
            }

#if NO
            SaLoginDialog dlg = new SaLoginDialog();
            GuiUtil.AutoSetDefaultFont(dlg);
            dlg.SqlServerName = this.textBox_sqlServerName.Text;
            dlg.StartPosition = FormStartPosition.CenterScreen;

            dlg.ShowDialog(this);

            if (dlg.DialogResult != DialogResult.OK)
            {
                return;
            }
#endif

#if NO
            // 创建dp2Kernel登录名

            // 创建一个适合于dpKernel的SQL Server login
            // return:
            //      -1  出错
            //      0   成功
            //      1   原来已经存在,且不允许删除
            nRet = CreateLogin(
                this.SqlServerName,
                dlg.SqlUserName,
                dlg.SqlPassword,
                dlg.SSPI,
                this.textBox_loginName.Text,
                this.textBox_loginPassword.Text,
                out strError);
            if (nRet == -1 || nRet == 1)
            {
                goto ERROR1;
            }
#endif

            this.button_OK.Enabled = false;
            try
            {
                nRet = VerifySqlServer(
                    this.SqlServerName,
                    this.textBox_loginName.Text,
                    this.textBox_loginPassword.Text,
                    false,
                    out strError);
                if (nRet == -1)
                {
                    DialogResult result = MessageBox.Show(this,
                                                          "在检查服务器参数的过程中发生错误: \r\n\r\n"
                                                          + strError
                                                          + "\r\n\r\n是否依然采用这些参数继续完成安装?",
                                                          "MySqlDataSourceDlg",
                                                          MessageBoxButtons.YesNo,
                                                          MessageBoxIcon.Question,
                                                          MessageBoxDefaultButton.Button2);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        MessageBox.Show(this, "请修改服务器参数");
                        return;
                    }
                }
            }
            finally
            {
                this.button_OK.Enabled = true;
            }


            this.DialogResult = DialogResult.OK;
            this.Close();
            return;

ERROR1:
            MessageBox.Show(this, strError);
            // MessageBox.Show(this, "虽然刚才的创建登录名操作失败了,但您也可以在重新指定登录名和密码后,再次按“确定”按钮创建登录名,继续进行安装");
        }
Esempio n. 5
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            string strError = "";
            int nRet = 0;

            if (this.textBox_sqlServerName.Text == "")
            {
                strError = "尚未指定 MySQL 服务器";
                goto ERROR1;
            }

            if (string.Compare(this.textBox_sqlServerName.Text.Trim(), "~sqlite") == 0)
            {
                strError = "MySQL 服务器名不能为 '~sqlite',因为这个名字保留给了 SQLite 内置数据库类型";
                goto ERROR1;
            }

            if (this.textBox_loginName.Text == "")
            {
                strError = "尚未指定 MySQL 用户名";
                goto ERROR1;
            }

            if (this.textBox_loginPassword.Text != this.textBox_confirmLoginPassword.Text)
            {
                strError = "MySQL 帐户的密码和确认密码不一致";
                goto ERROR1;
            }

#if NO
            SaLoginDialog dlg = new SaLoginDialog();
            GuiUtil.AutoSetDefaultFont(dlg);
            dlg.SqlServerName = this.textBox_sqlServerName.Text;
            dlg.StartPosition = FormStartPosition.CenterScreen;

            dlg.ShowDialog(this);

            if (dlg.DialogResult != DialogResult.OK)
                return;
#endif

#if NO
            // 创建dp2Kernel登录名

            // 创建一个适合于dpKernel的SQL Server login
            // return:
            //      -1  出错
            //      0   成功
            //      1   原来已经存在,且不允许删除
            nRet = CreateLogin(
                this.SqlServerName,
                dlg.SqlUserName,
                dlg.SqlPassword,
                dlg.SSPI,
                this.textBox_loginName.Text,
                this.textBox_loginPassword.Text,
                out strError);
            if (nRet == -1 || nRet == 1)
                goto ERROR1;
#endif

            this.button_OK.Enabled = false;
            try
            {
                nRet = VerifySqlServer(
                    this.SqlServerName,
                    this.textBox_loginName.Text,
                    this.textBox_loginPassword.Text,
                    false,
                    out strError);
                if (nRet == -1)
                {
                    DialogResult result = MessageBox.Show(this,
    "在检查服务器参数的过程中发生错误: \r\n\r\n"
    + strError
    + "\r\n\r\n是否依然采用这些参数继续完成安装?",
    "MySqlDataSourceDlg",
    MessageBoxButtons.YesNo,
    MessageBoxIcon.Question,
    MessageBoxDefaultButton.Button2);
                    if (result == System.Windows.Forms.DialogResult.No)
                    {
                        MessageBox.Show(this, "请修改服务器参数");
                        return;
                    }
                }
            }
            finally
            {
                this.button_OK.Enabled = true;
            }


            this.DialogResult = DialogResult.OK;
            this.Close();
            return;
        ERROR1:
            MessageBox.Show(this, strError);
            // MessageBox.Show(this, "虽然刚才的创建登录名操作失败了,但您也可以在重新指定登录名和密码后,再次按“确定”按钮创建登录名,继续进行安装");
        }
Esempio n. 6
0
        private void button_OK_Click(object sender, EventArgs e)
        {
            string strError = "";
            int    nRet     = 0;

            if (this.textBox_sqlServerName.Text == "")
            {
                strError = "尚未指定 SQL 服务器";
                goto ERROR1;
            }

            if (string.Compare(this.textBox_sqlServerName.Text.Trim(), "~sqlite") == 0)
            {
                strError = "MS SQL 服务器名不能为 '~sqlite',因为这个名字保留给了 SQLite 内置数据库类型";
                goto ERROR1;
            }

#if NO
            // 获得 SQL Server 信息
            SqlServerInfo info = null;
            nRet = GetSqlServerInfo(
                this.SqlServerName,
                dlg.SqlUserName,
                dlg.SqlPassword,
                dlg.SSPI,
                out info,
                out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }
#endif

            nRet = GetIntegratedSecurityOnlyMode(this.textBox_sqlServerName.Text, out strError);
            if (nRet == -1)
            {
                MessageBox.Show(this, strError);
            }

            bool bISOM = false;
            if (nRet == 1)
            {
                bISOM = true;
            }

            // 集成权限登录唯一方式的情况下,不要创建 登录名
            if (bISOM == true)
            {
                this.textBox_loginName.Text            = "";
                this.textBox_loginPassword.Text        = "";
                this.textBox_confirmLoginPassword.Text = "";
            }
            else
            {
                if (this.textBox_loginName.Text == "")
                {
                    strError = "尚未指定 dp2Kernel 登录名";
                    goto ERROR1;
                }

                if (this.textBox_loginPassword.Text != this.textBox_confirmLoginPassword.Text)
                {
                    strError = "dp2Kernel 登录名的密码和确认密码不一致";
                    goto ERROR1;
                }
            }

            /*
             * if (this.SSPI == false && this.textBox_sqlUserName.Text == "")
             * {
             *  MessageBox.Show(this, "尚未指定SQL帐号。");
             *  return;
             * }
             *
             *
             * // 检测SQL帐户是否正确
             * EnableControls(false);
             * string strError = "";
             * int nRet = this.detect(this.textBox_sqlServerName.Text,
             *  this.textBox_sqlUserName.Text,
             *  this.textBox_sqlPassword.Text,
             *  radioButton_SSPI.Checked,
             *  out strError);
             * EnableControls(true);
             * if (nRet == -1)
             * {
             *  strError = strError + "\r\n" + "请重新指定服务器信息。";
             *  MessageBox.Show(this, strError);
             *  return;
             * }
             * */

            SaLoginDialog dlg = new SaLoginDialog();
            GuiUtil.AutoSetDefaultFont(dlg);
            dlg.SqlServerName = this.textBox_sqlServerName.Text;
            dlg.StartPosition = FormStartPosition.CenterScreen;

            dlg.ShowDialog(this);

            if (dlg.DialogResult != DialogResult.OK)
            {
                return;
            }

            if (string.IsNullOrEmpty(this.textBox_loginName.Text) == false)
            {
                // 创建dp2Kernel登录名

                // 创建一个适合于dpKernel的SQL Server login
                // return:
                //      -1  出错
                //      0   成功
                //      1   原来已经存在,且不允许删除
                nRet = CreateLogin(
                    this.SqlServerName,
                    dlg.SqlUserName,
                    dlg.SqlPassword,
                    dlg.SSPI,
                    this.textBox_loginName.Text,
                    this.textBox_loginPassword.Text,
                    out strError);
                if (nRet == -1 || nRet == 1)
                {
                    goto ERROR1;
                }
            }

            if (bISOM == true)
            {
                nRet = AddSystemDbCreatorRole(
                    this.SqlServerName,
                    dlg.SqlUserName,
                    dlg.SqlPassword,
                    dlg.SSPI,
                    out strError);
                if (nRet == -1)
                {
                    strError = "为 登录名 'NT AUTHORITY\\SYSTEM' 添加 'dbcreator' 时出错: " + strError;
                    goto ERROR1;
                }
            }

            /*
             * if (nRet == 1)
             * {
             *  string strText = "登录名 '" + this.textBox_loginName.Text + "' 在SQL服务器 '" + this.SqlServerName + "' 中已经存在,但其密码不一定和当前指定的密码相同。\r\n\r\n是否继续使用这个登录名?\r\n(Yes)继续使用;(No)重新指定登录名和密码";
             *  DialogResult result = MessageBox.Show(this,
             *      strText,
             *      "setup_dp2Kernel",
             *      MessageBoxButtons.YesNo,
             *      MessageBoxIcon.Question,
             *      MessageBoxDefaultButton.Button2);
             *  if (result == DialogResult.No)
             *  {
             *      this.textBox_loginPassword.Focus();
             *      return;
             *  }
             * }
             * */

            this.DialogResult = DialogResult.OK;
            this.Close();
            return;

ERROR1:
            MessageBox.Show(this, strError);
            MessageBox.Show(this, "虽然刚才的创建登录名操作失败了,但您也可以在重新指定登录名和密码后,再次按“确定”按钮创建登录名,继续进行安装");
        }