コード例 #1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            StringBuilder connStr = new StringBuilder($"data source={cbServer.Text};initial catalog={txtDBName.Text};Integrated Security=True;MultipleActiveResultSets=True;App=EntityFramework;User Id={txtUsername.Text};Password={txtPassword.Text};Persist Security Info=True");

            ESPDatabase  database = null;
            DialogResult res      = DialogResult.OK;

            try
            {
                database = new ESPDatabase(connStr.ToString());
                if (null == database.Database.Connection)
                {
                    res = MessageBox.Show("Cannot connect to database.", "Database connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (database.Database.Connection.State != ConnectionState.Open)
                {
                    if (!database.Database.Exists())
                    {
                        res = MessageBox.Show("Cannot connect to database.", "Database connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                res = MessageBox.Show(ex.Message, "Database connection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DB           = database;
            DialogResult = DialogResult.OK;
            this.Close();
        }
コード例 #2
0
        public frmMain(ESPDatabase db = null)
        {
            InitializeComponent();
            Mode = EditorMode.None;

            DB = db ?? new ESPDatabase();
        }
コード例 #3
0
 public frmDBSelection()
 {
     InitializeComponent();
     DB = null;
 }