Beispiel #1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (CheckInput())
            {
                try
                {
                    var conBuilder = BuildConnection();
                    var sqlComment = "select 1 as value from sys.databases";
                    var sqlHelper  = new Common.SqlHelper();
                    var result     = sqlHelper.ExecuteScalar <int>(conBuilder.ToString(), sqlComment);
                    if (result > 0)
                    {
                        WirteFle();
                        int dbId = 0;
                        try
                        {
                            Common.DataService.SaveDataBase(conBuilder.DataSource, conBuilder.InitialCatalog);
                            dbId = Common.DataService.GetDataBaseID(conBuilder.DataSource, conBuilder.InitialCatalog);
                        }
                        catch (Exception ex)
                        {
                            Logger.Error("保存登录的数据库信息失败", ex);
                        }

                        var mainFrom = new Main(conBuilder);
                        mainFrom.LoginForm     = this;
                        mainFrom.StartPosition = FormStartPosition.CenterScreen;
                        mainFrom.DataBaseID    = dbId;
                        mainFrom.Show();

                        this.Hide();
                    }
                    else
                    {
                        MessageHelper.ShowMessage("连接数据库失败", "Waring");
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("读取数据库信息失败", ex);
                    MessageHelper.ShowMessage(ex.Message, "Error");
                }
            }
        }
Beispiel #2
0
 private void btnTest_Click(object sender, EventArgs e)
 {
     if (CheckInput())
     {
         try
         {
             var conBuilder = BuildConnection();
             var sqlComment = "select name as txt,name as value from sys.databases";
             var sqlHelper  = new Common.SqlHelper();
             var dtDbs      = sqlHelper.ExecuteQuery(conBuilder.ToString(), sqlComment);
             this.cboDataBases.DataSource    = dtDbs;
             this.cboDataBases.DisplayMember = "text";
             this.cboDataBases.ValueMember   = "value";
             MessageHelper.ShowMessage("连接成功");
         }
         catch (Exception ex)
         {
             Logger.Error("读取数据库信息失败", ex);
             MessageHelper.ShowMessage(ex.Message, "Error");
         }
     }
 }