ALTER DATABASE 数据库名 SET ENABLE_BROKER
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//引用命名空间
using System.Data.SqlClient;
using System.Web.Caching;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
//显示页面创建的时间
lblTime.Text =System.DateTime.Now.ToString();
DataSet dataSet = newDataSet();
string connString ="Data Source=accp;Initial Catalog=MyBookShop;User ID=sa;Pwd=123";
//CacheDependency dep=newCacheDependency("E:\\新建文件夹\\第4章\\源代码\\文本文档.txt");
//启动接收依赖项更改通知的监听器
SqlDependency.Start(connString);
if(Cache["dt"] == null)
{
SqlConnection connection = new SqlConnection(connString);
string sql= "SELECT title书名,author作者,publishdate 出版日期,unitprice 单价,clicks 点击次数 FROM dbo.books";
SqlCommandcommand = new SqlCommand(sql,connection);
// Createa dependency and associate it with the SqlCommand.
SqlCacheDependency dependency = new SqlCacheDependency(command);
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(dataSet);
Cache.Add("dt", dataSet, dep, DateTime.Now.AddMinutes(2),Cache.NoSlidingExpiration, CacheItemPriority.High, null);
}
else
{
dataSet =Cache["dt"] as DataSet;
}
gvBooksInfo.DataSource =dataSet;
gvBooksInfo.DataBind();
}
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//
using System.Data.SqlClient;
using System.Web.Caching;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
//
lblTime.Text =System.DateTime.Now.ToString();
DataSet dataSet = newDataSet();
string connString ="Data Source=accp;Initial Catalog=MyBookShop;User ID=sa;Pwd=123";
//CacheDependency dep=newCacheDependency("E:\\
//
SqlDependency.Start(connString);
if(Cache["dt"] == null)
{
SqlConnection connection = new SqlConnection(connString);
string sql= "SELECT title
SqlCommandcommand = new SqlCommand(sql,connection);
// Createa dependency and associate it with the SqlCommand.
SqlCacheDependency dependency = new SqlCacheDependency(command);
SqlDataAdapter adapter = new SqlDataAdapter(command);
adapter.Fill(dataSet);
Cache.Add("dt", dataSet, dep, DateTime.Now.AddMinutes(2),Cache.NoSlidingExpiration, CacheItemPriority.High, null);
}
else
{
dataSet =Cache["dt"] as DataSet;
}
gvBooksInfo.DataSource =dataSet;
gvBooksInfo.DataBind();
}
}
浙公网安备 33010602011771号