private void btn_ConTest_Click(object sender, EventArgs e) { try { string server = this.comboBoxServer.Text.Trim(); string user = this.txtUser.Text.Trim(); string pass = this.txtPass.Text.Trim(); string port = this.textBox1.Text.Trim(); if ((user == "") || (server == "")) { MessageBox.Show(this, "服务器或用户名不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } constr = String.Format("server={0};uid={1}; Port={2};pwd={3}; database=mysql; pooling=false", server, user, port, pass); try { this.Text = "正在连接服务器,请稍候..."; LTP.IDBO.IDbObject dbobj; dbobj = LTP.DBFactory.DBOMaker.CreateDbObj("MySQL"); dbobj.DbConnectStr = constr; List <string> dblist = dbobj.GetDBList(); this.cmbDBlist.Enabled = true; this.cmbDBlist.Items.Clear(); this.cmbDBlist.Items.Add("全部库");//5_1_a_s_p_x if (dblist != null) { if (dblist.Count > 0) { foreach (string dbname in dblist) { this.cmbDBlist.Items.Add(dbname); } } } this.cmbDBlist.SelectedIndex = 0; this.Text = "连接服务器成功!"; } catch (System.Exception ex) { LogInfo.WriteLog(ex); this.Text = "连接服务器或获取数据信息失败!"; DialogResult drs = MessageBox.Show(this, "连接服务器或获取数据信息失败!\r\n请检查服务器地址或用户名密码是否正确!查看帮助文件以帮助您解决问题?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (drs == DialogResult.OK) { try { Process proc = new Process(); Process.Start("IExplore.exe", "http://help.maticsoft.com"); } catch { MessageBox.Show("请访问:http://www.maticsoft.com", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information); } } return; } } catch (System.Exception ex) { LogInfo.WriteLog(ex); MessageBox.Show(this, ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void btn_ConTest_Click(object sender, System.EventArgs e) { try { string server = this.comboBoxServer.Text.Trim(); string user = this.txtUser.Text.Trim(); string pass = this.txtPass.Text.Trim(); if ((user == "") || (server == "")) { MessageBox.Show(this, "服务器或用户名不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (GetSelVerified() == "Windows") { constr = "Integrated Security=SSPI;Data Source=" + server + ";Initial Catalog=master"; } else { if (pass == "") { constr = "user id=" + user + ";initial catalog=master;data source=" + server; } else { constr = "user id=" + user + ";password="******";initial catalog=master;data source=" + server; } } string strtype = GetSelVer(); #region 判断版本 GetSelVer() try { string ver = GetSQLVer(constr); if ((ver == "8") && (strtype == "SQL2005")) { DialogResult dr = MessageBox.Show(this, "该数据库服务器版本并非SQLServer 2005,是否进行重新选择?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (dr == DialogResult.OK) { //comboBoxServerVer.SelectedIndex = 1; return; } } if ((ver == "9") && (strtype == "SQL2000")) { DialogResult dr = MessageBox.Show(this, "该数据库服务器版本并非SQLServer 2000,是否进行重新选择?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (dr == DialogResult.OK) { //comboBoxServerVer.SelectedIndex = 0; return; } } } catch { } #endregion try { this.Text = "正在连接服务器,请稍候..."; LTP.IDBO.IDbObject dbobj; dbobj = LTP.DBFactory.DBOMaker.CreateDbObj(strtype); dbobj.DbConnectStr = constr; List <string> dblist = dbobj.GetDBList(); this.cmbDBlist.Enabled = true; this.cmbDBlist.Items.Clear(); this.cmbDBlist.Items.Add("全部库"); if (dblist != null) { if (dblist.Count > 0) { foreach (string dbname in dblist) { this.cmbDBlist.Items.Add(dbname); } } } this.cmbDBlist.SelectedIndex = 0; this.Text = "连接服务器成功!"; } catch (System.Exception ex) { LogInfo.WriteLog(ex); this.Text = "连接服务器或获取数据信息失败!"; string strinfo = "连接服务器或获取数据信息失败!\r\n"; strinfo += "请检查服务器地址或用户名密码是否正确!\r\n"; strinfo += "如果连接失败,服务器名可以用 “(local)”或是“.” 或者“机器名” 试一下!\r\n"; strinfo += "如果需要查看帮助文件以帮助您解决问题,请点“确定”,否则点“取消”"; DialogResult drs = MessageBox.Show(this, strinfo, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); if (drs == DialogResult.OK) { try { Process proc = new Process(); Process.Start("IExplore.exe", "http://help.maticsoft.com"); } catch { MessageBox.Show("请访问:http://www.maticsoft.com", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information); } } return; } } catch (System.Exception ex) { //LogInfo.WriteLog(System.Reflection.MethodBase.GetCurrentMethod(), ex); LogInfo.WriteLog(ex); MessageBox.Show(this, ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }