private void ConnectDBServer() { //连接数据库 lblStatus.Text = "正在连接数据库服务器..."; AppDC.DBServer = txtServer.Text.Trim(); AppDC.DBName = txtDB.Text.Trim(); AppDC.UserName = txtUserName.Text.Trim(); AppDC.Password = txtPassword.Text.Trim(); LoginDS = new SqlsvrDBSource(AppDC); if (!LoginDS.Connect()) { string errMsg = LoginDS.ErrorMessage; errMsg = "数据库服务器连接不正确,请重新设置!错误信息:" + errMsg; lblStatus.Text = errMsg; //MessageBox.Show(errMsg); return; } else { lblStatus.Text = ""; } if (!string.IsNullOrEmpty(_userName)) { txtLoginUser.Text = _userName; txtLoginPassword.Text = _password; btnLogin_Click(this, null); } ThreadEnd te = new ThreadEnd(OnThreadEnd); this.BeginInvoke(te); }
private void btnConnectTest_Click(object sender, EventArgs e) { AppDC.DBServer = txtServer.Text.Trim(); AppDC.DBName = txtDB.Text.Trim(); AppDC.UserName = txtUserName.Text.Trim(); AppDC.Password = txtPassword.Text.Trim(); LoginDS = new SqlsvrDBSource(AppDC); if (LoginDS.Connect()) { MessageBox.Show("连接成功!"); } else { string errMsg = LoginDS.ErrorMessage; MessageBox.Show(errMsg); return; } }