Ejemplo n.º 1
0
        private void PopulateServerNames()
        {
            if (this.refreshServerListOnDropDown)
            {
                this.Cursor = Cursors.WaitCursor;
                Application.DoEvents();

                ArrayList servers = SqlServerLocator.FindServers();
                SQLServerComboBox.Items.Clear();

                if (servers != null)
                {
                    foreach (string server in servers)
                    {
                        if (server.ToLower() == "(local)")
                        {
                            SQLServerComboBox.Items.Add(Environment.MachineName.ToUpper());
                        }
                        else
                        {
                            SQLServerComboBox.Items.Add(server);
                        }
                    }

                    SQLServerComboBox.SelectedItem = SQLServerComboBox.Items[0];
                }

                this.Cursor = Cursors.Default;
                this.refreshServerListOnDropDown = false;
            }
        }
Ejemplo n.º 2
0
        private void PopulateDatabaseNamesList()
        {
            if (this.SQLServerComboBox.Text != null && this.SQLServerComboBox.Text.Length > 0)
            {
                this.SQLDatabaseComboBox.Enabled      = false;
                this.SQLDatabaseComboBox.SelectedItem = null;
                this.SQLDatabaseComboBox.Text         = "Querying available databases...";
                this.SQLDatabaseComboBox.Items.Clear();
                Application.DoEvents();
                Cursor.Current = Cursors.WaitCursor;

                string serverName = this.SQLServerComboBox.Text as string;

                foreach (string databaseName in SqlServerLocator.FindDatabases(serverName))
                {
                    // Do not allow any of these specified databases
                    if (string.Compare(databaseName, "master", true) != 0 &&
                        string.Compare(databaseName, "msdb", true) != 0 &&
                        string.Compare(databaseName, "tempdb", true) != 0 &&
                        string.Compare(databaseName, "model", true) != 0)
                    {
                        this.SQLDatabaseComboBox.Items.Add(databaseName.ToUpper());
                    }
                }

                // Set the initial database
                if (this.SQLDatabaseComboBox.Items.Count > 0)
                {
                    // Do we have a pre loaded database name?
                    if (this.initialCatalog != null && this.initialCatalog.Length > 0 && this.SQLDatabaseComboBox.Items.Contains(this.initialCatalog))
                    {
                        // Yes, set it
                        this.DatabaseName = this.initialCatalog;
                    }
                    else
                    {
                        // No, then set the first item
                        this.SQLDatabaseComboBox.SelectedItem = this.SQLDatabaseComboBox.Items[0];
                    }
                }
                else
                {
                    // No DB's returned, clear this out then
                    this.DatabaseName = "";
                }


                if (this.SQLSelectDatabaseRadioButton.Checked)
                {
                    this.SQLDatabaseComboBox.Enabled = true;
                }
                Cursor.Current = Cursors.Default;
            }
        }