报没有找到数据库,或数据库拒绝访问.  有时有这个问题. 有时没有.  但我用查询分析器 异地访问 都没有问题.

解决方案 »

  1.   

    public static int ExecuteNonQuery(string cmdText, CommandType cmdtype)
    {
    int retVal = 0;
    using (SqlConnection conn = new SqlConnection(connStr))
    {
    SqlCommand cmd = new SqlCommand(cmdText, conn);
    cmd.CommandType = cmdtype; try {
    conn.Open();
    retVal = cmd.ExecuteNonQuery();
    }
    catch(Exception exp){
    //如果发生错误,则转到错误显示页面
    HttpContext.Current.Response.Redirect("errMessage.aspx?errMsg=" + HttpContext.Current.Server.UrlEncode(exp.Message));
    HttpContext.Current.Response.End();
    }
    finally {
    conn.Close();
    }
    }
    return retVal;
    }