Example #1
0
        public bool Connect(bool showMessage)
        {
            Cursor      = Cursors.WaitCursor;
            IsConnected = false;

            try
            {
                string cs;
                if (IsBuild())
                {
                    var ctrls = controls.ToDictionary(p => p.Control);
                    DbConnectionStringBuilder csb = Database.BuildConnectionString(providerType, ctrls[txtHost].Text, ctrls[txtDatabase].Text, ctrls[txtUserId].Text, ctrls[txtPassword].Text, ctrls[chkIntegSec].Boolean, ctrls[numPort].Integer, ctrls[chkEmbedded].Boolean);
                    cs = csb.ConnectionString;
                }
                else
                {
                    cs = txtConnectionString.Text.Trim();
                }

                if (!string.IsNullOrEmpty(cs))
                {
                    using (var db = new Database(providerType, cs))
                    {
                        db.Open();
                        db.Close();
                    }
                    ViewToData();
                    IsConnected = true;
                }
                else
                {
                    throw new Exception("Invalid connection string");
                }

                if (showMessage)
                {
                    ProgramBase.ShowInformation("Database set up successfully: '" + txtDatabase.Text + "'");
                }
            }
            catch (Exception ex)
            {
                if (showMessage)
                {
                    ProgramBase.ShowError(ex);
                }
                IsConnected = false;
            }
            Cursor = Cursors.Default;
            Draw();
            SetControls();
            return(IsConnected);
        }