コード例 #1
0
        private void serverNameCoboBox_DropDown(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                SqlConnectionStringBuilder connectionBuilder;

                connectionBuilder = new SqlConnectionStringBuilder( );

                connectionBuilder.DataSource         = serverNameCoboBox.Text;
                connectionBuilder.IntegratedSecurity = windowsAuthenticationRadioButton.Checked;
                connectionBuilder.UserID             = userNameTextBox.Text;
                connectionBuilder.Password           = passwordTextBox.Text;

                serverDatabaseComboBox.DataSource = SqlUtilities.GetDatabaseList(connectionBuilder);
            }
            catch (Exception exp)
            {
                serverDatabaseComboBox.DataSource = null;
                serverDatabaseComboBox.Items.Clear( );
                Messager.ShowError(this, exp);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
コード例 #2
0
        public static void DeleteDbIfExists(SqlConnectionStringBuilder csB)
        {
            if (SqlUtilities.DatabaseExist(csB))
            {
                string dbName;

                dbName = csB.InitialCatalog;


                try
                {
                    csB.InitialCatalog = "";

                    if (!SqlUtilities.IsDatabaseConnected(csB.ConnectionString, dbName))
                    {
                        csB.InitialCatalog = dbName;

                        SqlUtilities.DropDatabase(csB);
                    }
                    else
                    {
                        throw new InvalidOperationException(string.Format("Drop database failed. Users are connected to database {0}", dbName));
                    }
                }
                finally
                {
                    csB.InitialCatalog = dbName;
                }
            }
        }
コード例 #3
0
        public static void CloseDatabaseConnections(
            string connectionString,
            string strDatabaseName
            )
        {
            if (!SqlUtilities.IsDatabaseConnected(connectionString, strDatabaseName))
            {
                return;
            }

            InternalCloseDatabaseConnections(connectionString, strDatabaseName);
        }
コード例 #4
0
        public static void DeleteDbIfExists(SqlConnectionStringBuilder csB, int callbackFrequencyInMilliseconds, DatabaseCallback cb)
        {
            if (SqlUtilities.DatabaseExist(csB))
            {
                bool   databaseDropped = false;
                string dbName;
                string fop;

                dbName = csB.InitialCatalog;
                fop    = csB.FailoverPartner;

                try
                {
                    csB.InitialCatalog  = string.Empty;
                    csB.FailoverPartner = string.Empty;

                    SqlUtilities.CloseDatabaseConnections(csB.ConnectionString, dbName);

                    if (!SqlUtilities.IsDatabaseConnected(csB.ConnectionString, dbName))
                    {
                        csB.InitialCatalog  = dbName;
                        csB.FailoverPartner = fop;

                        SqlUtilities.DropDatabase(csB, callbackFrequencyInMilliseconds, cb);
                        databaseDropped = true;
                    }
                }
                finally
                {
                    csB.InitialCatalog  = dbName;
                    csB.FailoverPartner = fop;
                }

                if (databaseDropped == false)
                {
                    try
                    {
                        csB.InitialCatalog  = dbName;
                        csB.FailoverPartner = fop;

                        SqlUtilities.DropDatabase(csB, callbackFrequencyInMilliseconds, cb);
                        databaseDropped = true;
                    }
                    catch (Exception)
                    {
                        throw new InvalidOperationException(string.Format("Drop database failed. Users are connected to database {0}", dbName));
                    }
                }
            }
        }
コード例 #5
0
        void SqlServerConfiguration_Load(object sender, EventArgs e)
        {
            if (_DesignMode)
            {
                return;
            }

            this.Cursor = Cursors.WaitCursor;

            try
            {
                string [] locals;

                try
                {
                    locals = SqlUtilities.GetLocalSQLServerInstances( );
                }
                catch (Exception)
                {
                    locals = new string [0];
                }


                if (locals != null && locals.Length > 0)
                {
                    serverNameCoboBox.Text = locals [0];
                }

                if (string.IsNullOrEmpty(serverDatabaseComboBox.Text))
                {
                    serverDatabaseComboBox.Text = DefaultDatabaseName;
                }

                if (!_DesignMode)
                {
                    string currentServer = serverNameCoboBox.Text;


                    serverNameCoboBox.DataSource = SqlUtilities.GetServerList( );

                    if (!string.IsNullOrEmpty(currentServer))
                    {
                        serverNameCoboBox.Text = currentServer;
                    }
                }
            }
            catch (Exception exception)
            {
                try
                {
                    //last time try to get the local servers.
                    serverNameCoboBox.DataSource = SqlUtilities.GetLocalSQLServerInstances( );
                }
                catch (Exception)
                {}

                Messager.ShowError(this, exception);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }