private bool CreateDatabase()
        {
            bool   error         = false;
            string connectString = SqlServers.BuildConnectionString(optCreationIntegratedSecurity.Checked, string.Empty, cboCreationServerName.Text, txtCreationUserName.Text, txtCreationPassword.Text);

            if (SqlServers.TestConnectionString(connectString) && SqlServers.HasCreatePermissions(connectString))
            {
                try
                {
                    var setup = new InstallSetup()
                    {
                        MasterConnectionString = connectString,
                        NewDatabaseName        = txtCreationDatabaseName.Text,
                    };
                    SqlServers.CreateDatabase(setup);
                }
                catch (Exception ex)
                {
                    error = true;
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
                    MessageBox.Show("Could not create database." + Environment.NewLine + ex.Message);
                }
            }
            else
            {
                error = true;
                MessageBox.Show("The account does not have permissions to create a database on this server.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(error);
        }
        private string[] GetDatabaseNames()
        {
            var connectString = SqlServers.BuildConnectionString(optConnectionIntegratedSecurity.Checked,
                                                                 cboConnectionDatabaseName.Text,
                                                                 cboConnectionServerName.Text,
                                                                 txtConnectionUserName.Text,
                                                                 txtConnectionPassword.Text);

            return(SqlServers.GetDatabaseNames(connectString));
        }
        private void cmdViewHistory_Click(object sender, EventArgs e)
        {
            string connectionString = SqlServers.BuildConnectionString(optConnectionIntegratedSecurity.Checked, cboConnectionDatabaseName.Text, cboConnectionServerName.Text, txtConnectionUserName.Text, txtConnectionPassword.Text);

            if (!SqlServers.TestConnectionString(connectionString))
            {
                MessageBox.Show("The information does not describe a valid connection string.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            HistoryForm F = new HistoryForm(connectionString);

            F.Show();
        }
        private void buttonConnectionTestConnection_Click(object sender, System.EventArgs e)
        {
            string connectString = SqlServers.BuildConnectionString(optConnectionIntegratedSecurity.Checked, cboConnectionDatabaseName.Text, cboConnectionServerName.Text, txtConnectionUserName.Text, txtConnectionPassword.Text);
            bool   valid         = SqlServers.TestConnectionString(connectString);

            if (valid)
            {
                MessageBox.Show("Connection Succeeded.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("The information does not describe a valid connection string.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #5
0
        private void cmdOK_Click(object sender, System.EventArgs e)
        {
            this.SaveSettings();
            if (tabControlChooseDatabase.SelectedTab == this.tabPageConnection)
            {
                var connectString = SqlServers.BuildConnectionString(optConnectionIntegratedSecurity.Checked, cboConnectionDatabaseName.Text, cboConnectionServerName.Text, txtConnectionUserName.Text, txtConnectionPassword.Text);
                var valid         = SqlServers.TestConnectionString(connectString);
                if (valid)
                {
                    this.InstallSettingsUI1.SaveUI(_setup);
                    this.Action       = ActionTypeConstants.Upgrade;
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("The information does not describe a valid connection string.");
                }
            }
            else if (tabControlChooseDatabase.SelectedTab == this.tabPageCreation)
            {
                bool error = false;
                if (_cbCreateDatabase.Checked)
                {
                    error = CreateDatabase();
                }

                if (!error)
                {
                    var outputConnectString = SqlServers.BuildConnectionString(optCreationIntegratedSecurity.Checked, txtCreationDatabaseName.Text, cboCreationServerName.Text, txtCreationUserName.Text, txtCreationPassword.Text);
                    if (SqlServers.TestConnectionString(outputConnectString))
                    {
                        //_connectionString = outputConnectString;
                        //_databaseName = cboCreationServerName.Text + "." + txtCreationDatabaseName.Text;
                        //_createdDb = true;
                    }
                    this.Action       = ActionTypeConstants.Create;
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            else if (tabControlChooseDatabase.SelectedTab == this.tabPageAzureCopy)
            {
                this.Action       = ActionTypeConstants.AzureCopy;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
        private bool CreateDatabase()
        {
            var error         = false;
            var connectString = SqlServers.BuildConnectionString(optCreationIntegratedSecurity.Checked, string.Empty, cboCreationServerName.Text, txtCreationUserName.Text, txtCreationPassword.Text);

            if (SqlServers.TestConnectionString(connectString) && SqlServers.HasCreatePermissions(connectString))
            {
                if (!string.IsNullOrWhiteSpace(txtDiskPath.Text) && !Directory.Exists(txtDiskPath.Text))
                {
                    error = true;
                    MessageBox.Show("The specified disk path does not exist.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(error);
                }

                try
                {
                    var setup = new InstallSetup()
                    {
                        MasterConnectionString = connectString,
                        NewDatabaseName        = txtCreationDatabaseName.Text,
                        DiskPath = txtDiskPath.Text.Trim(),
                    };
                    SqlServers.CreateDatabase(setup);
                }
                catch (Exception ex)
                {
                    error = true;
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
                    MessageBox.Show("Could not create database." + Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                error = true;
                MessageBox.Show("The account does not have permissions to create a database on this server.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(error);
        }