Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.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
C# 如果存在队列且查询有效,则SqlDependency不是工作事件_C#_Sql_Sql Server 2012_Sqldependency - Fatal编程技术网

C# 如果存在队列且查询有效,则SqlDependency不是工作事件

C# 如果存在队列且查询有效,则SqlDependency不是工作事件,c#,sql,sql-server-2012,sqldependency,C#,Sql,Sql Server 2012,Sqldependency,使用以下代码,不会引发my OnChange事件: SqlDependency.Start(connectionString); SqlConnection conn = new SqlConnection(connectionString); conn.Open(); using (SqlCommand command = new SqlCommand( "SELECT Name, Description FRO

使用以下代码,不会引发my OnChange事件:

SqlDependency.Start(connectionString);

SqlConnection conn = new SqlConnection(connectionString);
   conn.Open();

                using (SqlCommand command = new SqlCommand(
                    "SELECT Name, Description FROM dbo.Boms",
                    conn))
                {

                    SqlDependency dep = new SqlDependency(command);
                    dep.OnChange += dep_OnChange;

                    // Execute the command.
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        // Process the DataReader.
                    }
                }
我在谷歌上搜索了对查询的任何可能约束,但我的查询似乎没有问题。 dep对象也已正确创建,但我尝试(成功)在Boms表中插入一条记录,但未收到任何反馈或事件。 在Sql Server 2012中,我每次启动应用程序时都会看到一个新队列

我在系统表中查找错误,但似乎一切正常

有什么提示可以让你至少明白问题出在哪里吗

谢谢

阅读,并获取故障排除提示

  • 使用探查器,监视以查看QN订阅是如何创建和通知的
  • 使用探查器,监视通知的传递方式,特别是检查传递是否失败
  • 使用探查器,监视以查看通知传递是否遇到安全问题
运行此操作以确保执行为沙盒上下文不会遇到孤立的dbo sid问题:

ALTER AUTHORIZATION ON database::[<yourdbname>] TO [sa];
将数据库上的授权:[]更改为[sa];

正在执行的进程是否具有select权限?@LIUFA:我没有写到我也使用了这个返回true的方法:
private bool CanRequestNotifications(){SqlClientPermission permission=new SqlClientPermission(PermissionState.Unrestricted);try{permission.Demand();return true;}catch(System.Exception){return false;}