Exemplo n.º 1
0
 private void OnCreateDbLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     PromptDialog dialog = new PromptDialog(base.ServiceProvider);
     dialog.EntryText = "Enter a name for the new database:";
     Label_0017:
     if (dialog.ShowDialog() == DialogResult.OK)
     {
         string s = dialog.EntryValue.Trim();
         string message = string.Empty;
         if (s.Length == 0)
         {
             message = "The name must not be empty.";
         }
         else if (s.Length > 0x7c)
         {
             message = "The name cannot be longer than 124 characters.";
         }
         else if (!SqlHelper.IsValidIdentifier(s))
         {
             message = "The name is not valid. Check that it contains valid characters and is not too long.";
         }
         if (message.Length > 0)
         {
             this.ReportError(message, "Unable to create a database with that name.");
             goto Label_0017;
         }
         this.CollectConnectionSettings();
         SqlDatabase database = new SqlDatabase(this.ConnectionSettings);
         try
         {
             database.Connect();
             database.CreateDatabase(SqlHelper.RemoveDelimiters(s));
             this._connectionSettings.Database = s;
             base.DialogResult = DialogResult.OK;
             base.Close();
         }
         catch (Exception exception)
         {
             this.ReportError(exception, "Could not create a new database.");
             goto Label_0017;
         }
         finally
         {
             database.Disconnect();
         }
     }
 }
Exemplo n.º 2
0
        private void OnAsyncConnectCompleted(object sender, AsyncTaskResultPostedEventArgs e)
        {
            this.Connecting = false;
            ConnectType data = (ConnectType) e.Data;
            ConnectionTask task = sender as ConnectionTask;
            this._databaseCombo.Text = this._savedDatabaseText;
            if (((task != this._connectionTask) || task.IsCanceled) && (task.Database != null))
            {
                try
                {
                    task.Database.Disconnect();
                }
                catch
                {
                }
                return;
            }
            if (task.Database == null)
            {
                this.ReportError(task.Exception, "Unable to connect to the database.");
                return;
            }
            this._databaseCombo.Items.Clear();
            switch (data)
            {
                case ConnectType.DropDown:
                    foreach (string str in task.Database.GetDatabaseNames())
                    {
                        this._databaseCombo.Items.Add(str);
                    }
                    try
                    {
                        this._skipDropDownEvent = true;
                        this._databaseCombo.DroppedDown = false;
                        Application.DoEvents();
                        this._databaseCombo.DroppedDown = true;
                        Application.DoEvents();
                        goto Label_0193;
                    }
                    finally
                    {
                        this._skipDropDownEvent = false;
                    }
                    break;

                case ConnectType.ConnectButton:
                    break;

                default:
                    goto Label_0193;
            }
            this.ConnectionSettings.Database = this._savedDatabaseText.Trim();
            SqlDatabase database = new SqlDatabase(this.ConnectionSettings);
            try
            {
                database.Connect();
                if (!database.DatabaseExists(this.ConnectionSettings.Database))
                {
                    throw new InvalidOperationException(string.Format("A database named '{0}' could not be found. Please check the connection settings and the spelling of the database name.", this.ConnectionSettings.Database));
                }
                base.DialogResult = DialogResult.OK;
                base.Close();
                return;
            }
            catch (Exception exception)
            {
                this.ReportError(exception.Message, "Unable to connect to the database.");
            }
            finally
            {
                database.Disconnect();
            }
            Label_0193:
            task.Database.Disconnect();
        }