【问题标题】:Sql Server not creating subscription for simple select query using SqlCacheDependencySql Server 没有为使用 SqlCacheDependency 的简单选择查询创建订阅
【发布时间】:2011-12-26 11:25:44
【问题描述】:

我试图实现一个简单的 SQLCacheDependency 来缓存我的 asp.net 应用程序中的对象。

在折断了很长一段时间后,我似乎陷入了死胡同,并认为外面的观点会有所帮助。

SqlCommand cmd = new SqlCommand("SELECT UserID,FirstName,MiddleName,LastName,Mobile#,EmailID,FriendlyName,Phone#,AboutMe,Scrap#,JobPosting#,Testimonial#,Blog#,Views#,LastVisitedOn,CurrentAddress,City,State,Country,PermanentAddress,HomeTown,Occupation,CurrentEmployer,LanguageSpeak,LanguageWrite,CreatedOn,NeedJob,ProfileRank,Status,CurrentEmployerID,PictureID,ReferredBy,lat,Long,Zoom,Gender,PinCode,PersonalStatus,DOB,PreferredLanguage,EmploymentHistory,AboutFamily,LastSchoolName,HasCertificate,CertificateMonthLength,CertificateDescription,CertificateSchoolUserId,CallTimes,CertificateType,CertificateTypes,Skills FROM mydb.dbo.UserInfo where UserID=10277",con);
System.Web.Caching.SqlCacheDependency dependency = new System.Web.Caching.SqlCacheDependency(cmd);
con.Open();
try
{
       SqlDataReader reader = cmd.ExecuteReader();
       while (reader.Read())
       {
             seUserInfo = new UserInfo(reader, false);
             this.Context.Cache.Add("Sean", seanUserInfo, dependency, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, new CacheItemRemovedCallback(ItemRemovedCallBack));
       }
}

但是这个项目一被添加就从缓存中删除。现在,在花了很多时间修复其他可能的原因(为数据库设置 ANSI NULLS ON 等)之后,我现在碰壁了。从 SQL Server Profiler 中,我看到订阅是使用以下文本数据触发的

<qnev:QNEvent xmlns:qnev="http://schemas.microsoft.com/SQL/Notifications/QueryNotificationProfiler">
<qnev:EventText>subscription fired</qnev:EventText>
<qnev:SubscriptionID>0</qnev:SubscriptionID>
<qnev:NotificationMsg>&lt;qn:QueryNotification xmlns:qn="http://schemas.microsoft.com/SQL/Notifications/QueryNotification" id="0" type="subscribe" source="statement" info="invalid" database_id="0" sid="0x2EB2AC37F2E7FF468D5DE0B591029EE7"&gt;&lt;qn:Message&gt;26119019-fef7-47ee-ac82-3cb56313670d;9fbb5459-bde4-494b-9b7d-8347be2ee4cb&lt;/qn:Message&gt;&lt;/qn:QueryNotification&gt;</qnev:NotificationMsg><qnev:BrokerDlg>9B1E5573-A52F-E111-8152-005056C00008</qnev:BrokerDlg></qnev:QNEvent>

您会注意到 type = subscribe 和 info = invalid。这让我感到惊讶。根据http://www.simple-talk.com/sql/t-sql-programming/using-and-monitoring-sql-2005-query-notification/http://msdn.microsoft.com/en-us/library/ms189308.aspx,当“提交的命令包含不支持通知的语句(例如,插入或更新)”时会发生这种情况,显然它是符合conditions specified for SqlDependency creation 的简单选择语句

那么我在这里错过了什么?这是最简单的方案,它不起作用!

【问题讨论】:

    标签: sql-server-2005 sqldependency sqlcachedependency


    【解决方案1】:

    好的,我也在 msdn 论坛上问过这个问题,并在那里得到了回答。我的问题是我使用的是三部分限定符 mydb.dbo.tablename 而不是两部分限定符 dbo.tablename 这是一个要求。

    http://social.msdn.microsoft.com/Forums/en-US/sqlservicebroker/thread/bc9ca094-a989-4403-82c6-7f608ed462ce

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-22
      • 2013-06-21
      • 1970-01-01
      • 1970-01-01
      • 2019-11-27
      • 2014-08-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多