日期:2014-05-18 浏览次数:21002 次
using (SqlConnection conn = new SqlConnection(Config.SQL_CONN_STR))
{
    while (true)
    {
        try
        {
            conn.Open();
        }
        catch (Exception ex)
        {
            if (conn.State == ConnectionState.Closed)
            {
                //把我的程序的状态栏的Label设置为断开
                sspsl_ConnState.Text = "断开";
            }
            else if (conn.State == ConnectionState.Open)
            {
                sspsl_ConnState.Text = "连通";
                conn.Close();
            }
            //下面三行是我自己写的异常记录日志,下面会把日志记录贴出来
            StackTrace st = new StackTrace(new StackFrame(true));
            StackFrame sf = st.GetFrame(0);
            Tool.WriteLog(true , ex , st , sf);
        }
        
        Thread.Sleep(1000);
    }
}