C# SqlDependency未在信号器上触发
数据库更改时未触发SqlDependency。我已经启用了数据库代理。当我使用insert语句从dn手动插入时,后跟C# SqlDependency未在信号器上触发,c#,asp.net,sqldependency,C#,Asp.net,Sqldependency,数据库更改时未触发SqlDependency。我已经启用了数据库代理。当我使用insert语句从dn手动插入时,后跟 ALTER DATABASE MyDB SET ENABLE\u BROKER操作被命中。有什么问题吗 void sqlDep_OnChange(object sender, SqlNotificationEventArgs e) { //or you can also check => if (e.Info == SqlNotificationInfo.Inser
ALTER DATABASE MyDB SET ENABLE\u 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);
}
}
void sqlDep\u OnChange(对象发送方,SqlNotificationEventArgs e)
{
//或者您也可以检查=>if(e.Info==SqlNotificationInfo.Insert),如果您只想为插入的记录发送通知
if(e.Type==SqlNotificationType.Change)
{
SqlDependency sqlDep=发送方作为SqlDependency;
sqlDep.OnChange-=sqlDep_OnChange;
//从这里我们将向客户端发送通知消息
var notificationHub=GlobalHost.ConnectionManager.GetHubContext();
notificationHub.Clients.All.notify(“添加”);
//重新注册通知
注册通知(DateTime.Now);
}
}
sqlDep\u OnChange(对象发送者,SqlNotificationEventArgs e)方法是如何注册的?可以添加代码吗?是否启用了SQL依赖关系?Start(“连接字符串”、“SQLServerServiceBroker队列”);我启用了SQLDependency,如下字符串con=ConfigurationManager.ConnectionString[“sqlconsting”].ConnectionString;SqlDependency.Start(con);如何创建“sql server service broker队列”