- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用以下代码来缓存,并依赖于“People”表的“Name”列的更改。但是,在一行中,如果其他列(例如“地址”列)发生更改,则依赖项也会触发并清除缓存。 (ASP.NET 4.0 与 SQL Server 2008。)
public string GetTheVals()
{
string vals = HttpContext.Current.Cache["TheCacheKey__X"] as string;
if (vals == null)
{
con = GetConnection();
SqlCommand cmd = new SqlCommand(@"
SELECT Name
FROM dbo.People
", con);
con.Open();
SqlCacheDependency sqlDependency = new SqlCacheDependency(cmd);
SqlDataReader rdr = null;
StringBuilder builder = new StringBuilder("");
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
builder.Append(rdr[0].ToString());
}
vals = builder.ToString();
HttpContext.Current.Cache.Insert("TheCacheKey__X", vals, sqlDependency, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(20));
CloseConnection(con);
}
return vals;
}
尽管据说在结果更改时会触发,但为什么当不在命令查询中的列的值更改时会触发?
You can also assign a delegate to the OnChange event, which will fire when the results change for an associated command.
还需要明确声明列,以便我们了解它将过滤掉表中的其他列并且不会触发。
The projected columns in the SELECT statement must be explicitly stated, and table names must be qualified with two-part names. Notice that this means that all tables referenced in the statement must be in the same database.
The statement may not use the asterisk (*) or table_name.* syntax to specify columns.
The statement must not contain subqueries, outer joins, or self-joins.
http://msdn.microsoft.com/en-us/library/ms181122(v=sql.105).aspx
最佳答案
根据MS help ,但是:
SQL Server sends a query notification for a subscription when one ofthe following events occurs:
Rows contained in the query results may have changed.
The subscription expires.
The server restarts.
The query notification subscription could not be created (for example,the SELECT statement does not conform to the requirements specified inCreating a Query for Notification.
The server is heavily loaded.
Objects that the subscription depends on are dropped or modified.
Notice that SQL Server may produce a query notification in response toevents that do not change the data, or in response to a change thatdoes not actually affect the results of the query. For example, whenan UPDATE statement changes one of the rows returned by the query, thenotification may fire even if the update to the row did not change thecolumns in the query results.
关于asp.net - SqlCacheDependency/SqlDependency 和列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12705454/
我想使用 SignalR 和 SQLDependency 仅从数据库获取更新的行。 表的状态列可以从多个应用程序更新。我需要的是,当此状态列更新时,我需要我的应用程序获取状态实时更新的记录。我正在尝试
我试图在 SignalR 项目中使用 SqlDependancy,但我似乎无法多次触发 OnChanged 事件。它最初在订阅事件上触发,但在对基础数据库进行更改后再也不会触发。我省略了我的 Sign
我们正在开发一个 WPF 应用程序,使用 SqlDependencies 来根据数据库更新应用程序。我们已经认识到几次,查询通知似乎是不规则的——应用程序不显示数据库的最新状态。一旦其他人更改了桌面上
我正在使用 SqlDependency 在某些表中的数据发生更改时获得通知。 private void subscribeBroker() { using (var c
是否可以在 C# 中为 Sql Server 运行 SqlDependency 而无需执行查询? 我有一些可以变得相当大的表。跨表执行查询以判断行是否已更改可能需要很长时间。 最佳答案 不,SqlDe
我想在我的项目中使用 SqlDependency,但是我想要依赖的表正被多个程序用于非常重要的目的。因此,他们必须能够在 SqlDependency 运行时插入此表。这可能吗? 我读过 this问题,
我刚刚从 Microsoft 官方来源复制了示例 http://msdn.microsoft.com/en-us/library/a52dhwx7(v=vs.80).aspx我对此感到困惑。运行应用程
我正在尝试使用 SqlDependency 编写代码来注册通知,但我无法让它工作。我首先尝试在 .Net 中使用 Visual Studio,然后将其编译为 Mono。这是我的代码:http://pa
我正在尝试让查询通知在 SQL Server 2012 上运行。我正在按照此链接中的教程进行操作:http://www.codeproject.com/Articles/144344/Query-No
背景: 在设置 SqlDependency 时,我使用了这些文章中的信息来为数据库用户提供所需的最低权限: Minimum Database Permissions Required for SqlD
我想在我的项目中使用 SQLDependency 和依赖注入(inject)。这是我的代码 public interface IAreaRepository { string GetAreaQu
我有一个简单的查询,事件在正确的时间触发。但是,一旦触发,SqlDependency 对象的属性 .HasChanges 始终设置为 true。 第一次触发 OnChange 时,SqlNotific
我有一个包含聊天信息的 mssql 表。它有计算列,有数百万行,并且正在被第三方应用程序使用/填充。现在我想使用此表在我的网站上显示聊天记录,并且将来可能能够使用 signalr 发送消息。我使用 s
我一直在使用 SqlDependency在 .NET 3.5 应用程序中使用超过 3 年没有任何问题。场景如下: 带有 SqlDependency 的中央窗口服务看一张 table (我们称这张 ta
我将表用作消息队列并使用 SqlDependency“注册”更新。在我读到的所有地方,人们都在说“注意它的局限性”,但没有具体说明它们是什么。据我了解,当表的更新频率非常高时,您会遇到问题;幸运的是,
我目前的情况是我有一个应用程序需要在新数据到达数据库表时得到通知。数据来自外部来源(我无法控制——这是唯一的集成选项)。当新数据到达时,我的应用程序需要采取某些操作——基本上是查询新数据、处理它、将结
我有一个关于 SqlDependency 的简短问题。我在故障转移群集中配置了两个 SQL 2005 服务器。 当事件节点更改时,我停止接收通知...我必须手动重新启动承载 SqlDependency
使用 SQLDependency 需要什么权限?我在网上查了书,但没有明确这一点。 最佳答案 这有效: CREATE SCHEMA sql_dependency_user --empty placeh
在过去 3 天为这个问题苦苦挣扎之后,我终于把我的问题放在这里了。 我正在尝试使用 SignalR 和 SqlDependency 构建一个实时应用程序。显然,SQLDependency 不工作。但是
我的数据库中有两个表,一个记录异常,另一个记录日志消息。 我正在利用 SqlDependency 对象在这些表更改时收到通知,以便我可以更新我的网络仪表板。我得到了这个工作: public IEnum
我是一名优秀的程序员,十分优秀!