Asp.net mvc 3 关于在mvc3中使用缓存
我正在使用MVC3,从数据库中获取国家表并存储在缓存中。它第一次从缓存中获取数据时,但当我刷新页面时,它只提供datatable模式。它只给我countryid、countryname和countrycode字段。但是它没有给我数据Asp.net mvc 3 关于在mvc3中使用缓存,asp.net-mvc-3,caching,Asp.net Mvc 3,Caching,我正在使用MVC3,从数据库中获取国家表并存储在缓存中。它第一次从缓存中获取数据时,但当我刷新页面时,它只提供datatable模式。它只给我countryid、countryname和countrycode字段。但是它没有给我数据 DataTable dt_Country = (DataTable)HttpContext.Current.Cache["Countries"]; if (dt_Country == null) { Data
DataTable dt_Country = (DataTable)HttpContext.Current.Cache["Countries"];
if (dt_Country == null)
{
DataTable dt_State1 = new DataTable();
SqlConnection con = new SqlConnection(Common.ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("ConstantsCountriesSelectAll", con);
SqlDataAdapter ada = new SqlDataAdapter(cmd);
ada.Fill(dt_State1);
HttpContext.Current.Cache["Countries"] = dt_State1;
dt_Country = (DataTable)HttpContext.Current.Cache["Countries"];
}
//dt_Country = (DataTable)HttpContext.Current.Cache["Countries"];
return dt_Country;
在将数据表放入缓存之前是否尝试关闭连接?可能是连接在某个未知点关闭?