Asp.net mvc 如何对每个seprate查询使用sqldependency并引发不同的事件
可能这个问题会重复,但我找不到。我正在为我的应用程序使用signer和sqldependency。我已成功执行了一个查询操作。但是我会为每个查询编写单独的sqldependency代码。sqldependency代码位于应用程序级别,或者对于每个查询是单独的 1) 如何对每个操作使用不同的查询 2) 如何调用不同的onchange事件Asp.net mvc 如何对每个seprate查询使用sqldependency并引发不同的事件,asp.net-mvc,signalr,sqldependency,Asp.net Mvc,Signalr,Sqldependency,可能这个问题会重复,但我找不到。我正在为我的应用程序使用signer和sqldependency。我已成功执行了一个查询操作。但是我会为每个查询编写单独的sqldependency代码。sqldependency代码位于应用程序级别,或者对于每个查询是单独的 1) 如何对每个操作使用不同的查询 2) 如何调用不同的onchange事件 public void RegisterNotification() { string connectionString = Configurati
public void RegisterNotification()
{ string connectionString = ConfigurationManager.ConnectionStrings["FFFConnention"].ConnectionString;
//We have selected the entire table as the command, so SQL Server executes this script and sees if there is a change in the result, raise the event
// how to use different query for each operation
string commandText = @"
Select
dbo.Notification.UserName
From dbo.Notification
";
//Start the SQL Dependency
SqlDependency.Start(connectionString);
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand(commandText, connection))
{
connection.Open();
var sqlDependency = new SqlDependency(command);
NotificationHub hub = new NotificationHub();
//how to call different onchange event
sqlDependency.OnChange += new OnChangeEventHandler(hub.sqlDependency_OnChange);
// NOTE: You have to execute the command, or the notification will never fire.
command.ExecuteScalar();
}
}
}