예제 #1
0
        /// <summary>
        /// button click handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnConvertToMO_Click(object sender, EventArgs e)
        {
            if (txtServer.Text.Equals(string.Empty))
            {
                txtServer.Focus();
                MessageBox.Show(@"Please enter the valid server name",
                                @"Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
            if (cmbAuth.SelectedIndex == -1)
            {
                cmbAuth.Focus();
                MessageBox.Show(@"Please choose authentication type!",
                                @"Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
            if (cmbDatabase.SelectedIndex == -1)
            {
                cmbDatabase.Focus();
                MessageBox.Show(@"Please choose database",
                                @"Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
            if (chkNewDatabase.Checked == false && cmbDatabase.Text.Equals(cmbDestination.Text))
            {
                MessageBox.Show(@"Source and destination are the same. Not allowed!",
                                @"Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            //Create inputs
            _i = new Inputs
            {
                ServerName           = txtServer.Text,
                DatabaseName         = cmbDatabase.Text,
                InMemoryDataBaseName = cmbDestination.Text,
                UserName             = txtUserName.Text,
                Password             = txtPassword.Text,
                IsWindows            = cmbAuth.SelectedIndex == 0,
                CreateNew            = chkNewDatabase.Checked
            };
            if (_i.CreateNew)
            {
                _i.InMemoryDataBaseName = $"{_i.DatabaseName}_InMem";
            }
            //create options
            _o = new Options {
                CopyData = chkCopyData.Checked
            };
            if (rbHash.Checked)
            {
                _o.UseHashIndexes = Options.IndexDecision.Hash;
            }
            else if (rbRange.Checked)
            {
                _o.UseHashIndexes = Options.IndexDecision.Range;
            }
            else
            {
                _o.UseHashIndexes = Options.IndexDecision.ExtendedPropery;
            }

            //o.DropOnDestination = chkDropOnDestination.Checked;
            var arr = txtSchemas.Text.Trim().Split(',');

            foreach (var s in arr)
            {
                if (s != "")
                {
                    _o.Schemas.Add(s);
                }
            }

            arr = txtTables.Text.Trim().Split(',');
            foreach (var s in arr)
            {
                if (s != "")
                {
                    _o.Tables.Add(s);
                }
            }

            Server server;

            try
            {
                var cnn = new ServerConnection(_i.ServerName);
                cnn.Connect();
                server = new Server(cnn);
            }
            catch (Exception ex)
            {
                MessageBox.Show($@"I'm unable to connect to the server {_i.ServerName}  {ex.Message}",
                                @"Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
            var isSysAdmin = ((int)DataAccess.ExecuteScalar(DataAccess.GetConnectionString(
                                                                txtServer.Text,
                                                                "master",
                                                                cmbAuth.SelectedIndex == 0,
                                                                txtUserName.Text, txtPassword.Text), @" SELECT IS_SRVROLEMEMBER ('sysadmin') ") == 1);

            if (isSysAdmin == false)
            {
                MessageBox.Show(@"You should connect as a member of sysadmin fixed server role",
                                @"Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }



            if (new Version(server.VersionString) < new Version(CServerVersion))
            {
                MessageBox.Show(@"The server has to be SQL2016 SP2 or higher",
                                @"Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (server.Databases[_i.DatabaseName] == null)
            {
                MessageBox.Show(@"Choose the database!",
                                @"Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                cmbDatabase.SelectedItem = null;
                return;
            }

            if (server.Databases[_i.DatabaseName].HasMemoryOptimizedObjects)
            {
                MessageBox.Show(@"The source database contains Memory Optimized FileGroup. It is not allowed!",
                                @"Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }
            var error = "";


            if (_i.CreateNew)
            {
                if (MessageBox.Show($@"You choose to create a new database {_i.DatabaseName}_InMem. Are you sure?",
                                    @"Question",
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
                if (Converter.Utility.CreateDatabase.Create(server, _i.DatabaseName + "_InMem", ref error, _cnf.FileGroupName, _cnf.FileName, _cnf.MoPath) == false)
                {
                    MessageBox.Show($@"An error occurs while creating the database! {Environment.NewLine} { error}",
                                    @"Error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                if (MessageBox.Show($@"You choose to convert the database {_i.DatabaseName.ToUpper()} to In-Mem  {
                                _i.InMemoryDataBaseName.ToUpper()
                            }.
                                                        Are you sure?",
                                    @"Question",
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == DialogResult.No)
                {
                    return;
                }
                if (Converter.Utility.CreateDatabase.Create(server, _i.InMemoryDataBaseName, ref error,
                                                            _cnf.FileGroupName, _cnf.FileName, _cnf.MoPath) == false)
                {
                    MessageBox.Show(@"An error occurs while creating the database!",
                                    @"Error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return;
                }
            }


            ProgressBar1.Visible = true;
            ProgressBar1.Minimum = 1;
            ProgressBar1.Maximum = server.Databases[_i.DatabaseName].Tables.Count;
            ProgressBar1.Step    = 1;
            ProgressBar1.Show();

            grpConnection.Enabled  = false;
            grpOptions.Enabled     = false;
            btnConvertToMO.Enabled = false;
            btnCancel.Enabled      = true;



            _t1             = DateTime.Now;
            _mainObr        = new Thread(StartConversion);
            Timer1.Enabled  = true;
            Timer1.Interval = 500;
            _mainObr.Start();
        }
예제 #2
0
 private void PictureBox1_Click(object sender, EventArgs e)
 {
     ProgressBar1.Show();
     Label3.Show();
     timer1.Start();
 }