0

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>&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「送信されたコマンドに、通知をサポートしないステートメント (INSERT や UPDATE など) が含まれていた」場合に発生します。これは、明らかに、SqlDependency の作成に指定された条件に準拠する単純な選択ステートメントです。

それで、私はここで何が欠けていますか?これは最も単純なシナリオですが、うまくいきません!

4

1 に答える 1

0

わかりました、msdn フォーラムでもこれを尋ねたところ、そこで回答がありました。私の問題は、要件である 2 つの部分の修飾子 dbo.tablename ではなく、3 つの部分の修飾子 mydb.dbo.tablename を使用していたことです。

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

于 2011-12-26T22:28:20.953 に答える