Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 如何对每个seprate查询使用sqldependency并引发不同的事件_Asp.net Mvc_Signalr_Sqldependency - Fatal编程技术网

Asp.net mvc 如何对每个seprate查询使用sqldependency并引发不同的事件

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

可能这个问题会重复,但我找不到。我正在为我的应用程序使用signer和sqldependency。我已成功执行了一个查询操作。但是我会为每个查询编写单独的sqldependency代码。sqldependency代码位于应用程序级别,或者对于每个查询是单独的

1) 如何对每个操作使用不同的查询

2) 如何调用不同的onchange事件

 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();
            }
        }
    }