首页 新闻 会员 周边

写下缓存依赖Demo,报异常:System.OutOfMemoryException,有人能帮忙指导下吗

0
[已解决问题] 解决于 2016-07-12 15:11
 1 public partial class WebForm1 : System.Web.UI.Page
 2     {
 3         private static readonly DataSet Ds = new DataSet();
 4         private static readonly string ConnectionStr = ConfigurationManager.ConnectionStrings["TestDb123"].ToString();
 5 
 6         protected void Page_Load(object sender, EventArgs e)
 7         {
 8 
 9 
10             //sql缓存依赖
11             if (Cache.Get("key") == null)
12             {
13                 //DataSet ds = null;
14                 //if (_ds == null)
15                 //{
16                 //    _ds = new DataSet();
17                 //}
18 
19                 var conStr = ConnectionStr;
20                 var conn = new SqlConnection(conStr);
21                 const string sql = @"SELECT MAX(ID) ID
22                                 FROM dbo.HuanCunYiLai (NOLOCK);";
23                 SqlCommand cmd = new SqlCommand(sql, conn);
24                 SqlDataAdapter sda = new SqlDataAdapter(cmd);
25 
26                 sda.Fill(Ds, "tb1");
27                 SqlCacheDependency dep = new SqlCacheDependency("Test", "HuanCunYiLai");  //Test对应配置项的缓存配置key ,后面是数据库表名
28 
29                 Cache.Insert("key", Ds.Tables["tb1"].Rows[0][0].ToString(), dep);
30             }
31             Response.Write(Cache.Get("key"));
32         }
33     }
反骨仔的主页 反骨仔 | 菜鸟二级 | 园豆:444
提问于:2016-05-31 10:33
< >
分享
最佳答案
1

OutOfMemoryException 说明系统可以使用的内存空间不足,但是仅凭这個异常类无法判断问题到底出在哪里,建议把异常堆栈和截图也发出来,不然大家怎么分析问题。

奖励园豆:5
吸氧羊与肥汰狼 | 菜鸟二级 |园豆:293 | 2016-05-31 13:55
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册