经常有网友在程序运行时数据库有时连接有问题,排查也比较麻烦所以写了一个小程序来实现这样的功能
public string connectionstring; //数据库连接字符串
protected SqlConnection BaseSqlConnection = new SqlConnection();//连接对象
protected SqlCommand BaseSqlCommand = new SqlCommand(); //命令对象
private void buttonConnect_Click(object sender, EventArgs e)
{
connectionstring = "data source=" + this.textBoxDatebaseIP.Text + ";UID=" + this.textBoxUser.Text + ";PWD=" + this.textBoxUserpassword.Text + ";DATABASE=" + this.textBoxDatebase.Text;
if (CheckConnecttion())
{
MessageBox.Show("成功连接!");
groupBox2.Enabled = true;
}
else
{
MessageBox.Show("连接失败!");
}
}
下载地址 http://download.csdn.net/source/2220936