asp.net アプリケーションでオブジェクトをキャッシュするために、単純な SQLCacheDependency を実装しようとしていました。
かなり長い間頭を壊した後、行き止まりにぶつかったようで、外の景色が助けになると思いました.
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 プロファイラーから、サブスクリプションが次のテキスト データで起動されていることがわかります
<qnev:QNEvent xmlns:qnev="http://schemas.microsoft.com/SQL/Notifications/QueryNotificationProfiler">
<qnev:EventText>subscription fired</qnev:EventText>
<qnev:SubscriptionID>0</qnev:SubscriptionID>
<qnev:NotificationMsg><qn:QueryNotification xmlns:qn="http://schemas.microsoft.com/SQL/Notifications/QueryNotification" id="0" type="subscribe" source="statement" info="invalid" database_id="0" sid="0x2EB2AC37F2E7FF468D5DE0B591029EE7"><qn:Message>26119019-fef7-47ee-ac82-3cb56313670d;9fbb5459-bde4-494b-9b7d-8347be2ee4cb</qn:Message></qn:QueryNotification></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「送信されたコマンドに、通知をサポートしないステートメント (INSERT や UPDATE など) が含まれていた」場合に発生します。これは、明らかに、SqlDependency の作成に指定された条件に準拠する単純な選択ステートメントです。
それで、私はここで何が欠けていますか?これは最も単純なシナリオですが、うまくいきません!