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