我已经在我的项目中实现了SQLCacheDependancy。参考以下链接 http://www.dotnetfunda.com/articles/show/1382/how-to-implement-sql-caching-in-aspnet-poll-based-sql-cache-dependency
我的问题是
创建的存储过程很少,例如AspNet_SqlCachePollingStoredProcedure
,AspNet_SqlCacheRegisterTableStoredProcedure
等。
如果我将SP的名称从AspNet_SqlCachePollingStoredProcedure
更改为SqlCachePollingStoredProcedure
,则我的代码无法正常工作。我希望SQLCacheDependancy类以这种方式期望SP名称。
有没有办法更改SP名称并使之生效?
string connStringName = "default";
string connString = System.Configuration.ConfigurationManager.ConnectionStrings[connStringName].ToString();
using (SqlConnection conn = new SqlConnection(connString)) {
// write the sql statement to execute
string sql = "SELECT ID, Name FROM TableName";
// instantiate the command object to fire
using (SqlCommand cmd = new SqlCommand(sql, conn)) {
// get the adapter object and attach the command object to it
using (SqlDataAdapter ad = new SqlDataAdapter(cmd)) {
// fire Fill method to fetch the data and fill into DataTable
ad.Fill(table);
}
}
SqlCacheDependency dependency = new SqlCacheDependency("NorthwindCache",
"TableName");
// store data into Cache
Cache.Insert("TableName", table, dependency);
lblMessage.Text += "<br />Being loaded from the database";