日期:2014-05-17  浏览次数:20560 次

asp.net 连接出错

public static SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstr"].ToString());

    public static int RunProcstr(string procName, params SqlParameter[] prams)
    {
        try
        {
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand(procName, conn);
            cmd.CommandType = CommandType.StoredProcedure;
            if (prams != null)
            {
                foreach (SqlParameter parameter in prams)
                {
                    cmd.Parameters.Add(parameter);
                }
            }
            if (cmd == null) return -1;
            cmd.ExecuteNonQuery();
            return 1;
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message, ex);
        }
        finally
        {
            conn.Close();
        }
    }

    public static int RunProcdsstr(string procName, ref DataSet ds, params SqlParameter[] prams)
    {
        SqlDataAdapter da = null;
        try
        {
            if (null == ds) ds = new DataSet();
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
   &n