SqlDependency不在SignalR上触发

时间:2019-09-05 12:58:03

标签: c# asp.net sqldependency

SqlDependency不会在数据库更改时触发。我已启用数据库代理。当我使用插入语句从dn手动插入后 ALTER DATABASE MyDB SET ENABLE_BROKER动作被击中。可能是什么问题?

void sqlDep_OnChange(object sender, SqlNotificationEventArgs e)
{
    //or you can also check => if (e.Info == SqlNotificationInfo.Insert) , if you want notification only for inserted record
    if (e.Type == SqlNotificationType.Change)
    {
        SqlDependency sqlDep = sender as SqlDependency;
        sqlDep.OnChange -= sqlDep_OnChange;

        //from here we will send notification message to client
        var notificationHub = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
        notificationHub.Clients.All.notify("added");
        //re-register notification
        RegisterNotification(DateTime.Now);
    }
}

0 个答案:

没有答案