string strConn; StatusWin frmStatus = new StatusWin();
frmStatus.Text="正在测试连接......请稍候";
frmStatus.Show();

strConn="...."
try
{
SqlConnection tstCnn=new SqlConnection();
tstCnn.ConnectionString = strConn;
tstCnn.Open();
tstCnn.Close(); MessageBox.Show("测试链接到数据库成功!","系统信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(System.Exception exc)
{
MessageBox.Show("连接数据库失败。错误原因:" + exc.Message,"数据库连接提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
frmStatus.Close();
}