質問

Our applications use a lot of shared components. Some of them have no need for caching, for example, Windows Services which process unmailed emails. You'd never cache that result set...

Problem is, since our shared data layer has been modified to use SqlCacheDependency, our services which don't start SqlDependency fail on database calls where the data layer requests a SqlCacheDependency object.

Which leads to the question - is there a way for our data classes to test to see if the broker service is listening (ie: has SqlDependency.Start(connectionString) been called)?

The SqlDependency object itself has no Enabled or similar property. Is there any way short of forcing the calling app to tell the data layer that SqlCaching is in use for the data layer to determine the state?

役に立ちましたか?

解決

Pretty much the answer is no. We ended up adding a config variable that if false or not present, causes the request to use SqlCacheDependency to be skipped.

他のヒント

SELECT * FROM sys.service_queues WHERE name LIKE 'SqlQueryNotificationService-%'

returns a 'SqlQueryNotificationService-[some guid]'

And if you look deep in the Non-public members of the SqlDependency _serverUserHash while debugging in the IDE, you'll find a collection that contains that same entry. If Microsoft would be so kind as to expose that, then yes.

In my case I have a class library which is used by some web applications. So I have no App.config. I also use the SqlCacheDependency in a static event. So I'm using a static boolean like:

if (!isCachingEnabled)
  isCachingEnabled = SqlDependency.Start(builder.ProviderConnectionString);

So far is working but I'm open to suggestions when using Class Libraries.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top