использую в signalR
public class ExampleHub : Hub, ITransientDependency
{
public override Task OnConnected()
{
Storage.ConnStr = WebConfigurationManager.ConnectionStrings["Default"].ConnectionString;
SqlDependency.Start(Storage.ConnStr);
Storage.Connection = new SqlConnection(Storage.ConnStr);
Storage.Connection.Open();
Storage.Command = new SqlCommand("SELECT [State] FROM[Test].[dbo].[State]", Storage.Connection);
Storage.Dependency = new SqlDependency(Storage.Command);
Storage.Dependency.OnChange += Dependency_OnChange;
Storage.Command.ExecuteReader();
.......
private void Dependency_OnChange(object sender, SqlNotificationEventArgs e)
{
}
......
public static class Storage
{
public static bool IsEnabled;
public static SqlConnection Connection;
public static SqlCommand Command;
public static SqlDependency Dependency;
public static string ConnStr;
}
Dependency_OnChange вызывается сразу после ExecuteReader и только 1 раз, во время изменений в базе ничего не происходит