【问题标题】:Cannot find the object "QueryNotificationErrorsQueue" because it does not exist or you do not have permissions找不到对象“QueryNotificationErrorsQueue”,因为它不存在或您没有权限
【发布时间】:2016-11-22 05:23:36
【问题描述】:

当有一些数据库更改时,我使用SqlDependecysignalR 将通知推送到客户端浏览器,我关注了thisthis 的帖子,并且在本地SqlExpress 版本11.0 和本地连接中一切正常字符串,但是当我使用生产连接字符串连接到托管在 GoDaddy 中的远程数据库时,我遇到了某种权限问题

工作本地连接字符串

<!--<add name="NotifyConnection" providerName="System.Data.SqlClient" connectionString=
"Data Source=.\SQLExpress;Initial Catalog=TestDB;Integrated Security=SSPI;" />-->

生产连接字符串

<add name="NotifyConnection" connectionString="Server=000.00.00.000;Database=TestDB;
User Id=UserName;Password=YourPassword;" providerName="System.Data.SqlClient" />

获取数据方法

public IEnumerable<Order> GetData()
{

using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings
["NotifyConnection"].ConnectionString))
{

using (SqlCommand command = connection.CreateCommand())
{

command.CommandType = CommandType.Text;

command.CommandText = "SELECT OrderID,CustomerID FROM dbo.[RestUser]";

command.Notification = null;

SqlDependency dependency = new SqlDependency(command);
dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

if (connection.State == ConnectionState.Closed)
connection.Open();

using (var reader = command.ExecuteReader())
return reader.Cast<IDataRecord>()   // Here the Error throws
       .Select(x => new Order()
       {
       OrderID = x.GetInt32(0),
       CustomerID = x.GetInt32(1)                   
       }).ToList();


 }
 }
 }

我尝试了什么?

我按照post 在 sql server 中授予权限,但不确定这种方法是否正确。

USE YourDatabaseName;

CREATE QUEUE NameChangeQueue;

CREATE SERVICE NameChangeService ON QUEUE NameChangeQueue ([http://schemas.microsoft.com/
SQL/Notifications/PostQueryNotification]);

GRANT SUBSCRIBE QUERY NOTIFICATIONS TO YourUserName; // Here i get this error:

//Cannot grant, deny, or revoke permissions to sa, dbo, entity owner, information_schema, 
  sys, or yourself.

ALTER DATABASE YourDatabaseName SET ENABLE_BROKER;  // Broker is already enabled

屏幕截图:

我是SqlDependency 的新手,如何解决这个问题?

任何帮助都会很棒。

【问题讨论】:

  • 查看this answer 中的网络和身份验证注意事项。另外,您在代码中的哪个位置调用SqlDependency.Start()
  • @Smudge202 感谢您的评论,我在 Appliaction_Start 中调用它,我们计划迁移到 azure,但在 azure 中不支持 SqlDependency,因此我们收到 this 错误,计划使用triggers 来跟踪使用signaR 的数据库更改,有更好的建议吗?
  • 就个人而言,我不是 SqlDependency 和 Trigger 方法的忠实拥护者。相反,我会考虑将消息发布到服务总线(或某种形式的队列)。一个侦听器可以将数据保存到数据库中(我相信您现在正在这样做),而另一个侦听器可以处理您的 SignalR 推送通知。它不仅解决了这个问题,还为您提供了一层抵御服务中断的弹性。这就是我的处理方式,但我知道这并不能直接解决您的 SqlDependency 问题,抱歉。
  • @stom 嗨,我也面临同样的问题。同样的要求同样的问题。你修复了这个错误吗?
  • @Narasappa,我遇到了 Go daddy 数据库服务器的问题,在共享主机中它们限制了一些功能,你在使用共享主机吗?并尝试使用 signalR 显示通知?

标签: sql-server asp.net-mvc signalr signalr.client sqldependency


【解决方案1】:

在共享主机中,因为它们限制了某些功能,所以我无法使用 SqlDependency,但这是我在 asp mvc 中播放没有 SqlDependency 的通知的解决方案

如果您是signalR 新手,请先尝试this 发帖创建简单的聊天网络应用程序。

我的要求是在商店发生新销售时播放通知

1.创建 SignalR 服务器集线器

将消息发送到所有客户端浏览器的 SignalR 服务器集线器类。

[HubName("PascalCaseNewSalesHub")]
public class NewSalesHub : Hub
{

    public void Send(string shopid)
    {
        // Call the alertNewSalesToPage method to update clients.

        Clients.All.alertNewSalesToPage(shopid);
    }

}

2。 PlaceOrder 视图中的 Javascript 发送方法

当客户为这家商店下新订单时,以下 javascript 代码会调用服务器集线器上的 Send 方法来更新客户端。

<script>

$(function () 
{
// Reference the auto-generated proxy for the hub.
var chat = $.connection.PascalCaseNewSalesHub;

var thisShopID = @(ViewBag.ShopID);


// Start the connection.
$.connection.hub.start().done(function () {

// Call the Send method on the hub to send this shops ID

chat.server.send(thisShopID);


});
});

3. ShopSales 视图中的 Javascript 客户端回调方法

服务器上的 hub 类调用这个 javascript 函数将内容更新推送到每个客户端。

<script type="text/javascript">
$(function () 
{

console.log('Page loaded');

// Declare a proxy to reference the hub.

var notifications = $.connection.PascalCaseNewSalesHub;

if (notifications != null)
{
 console.log('connected to SalesHUB proxy');
}

var thisShopID = @(ViewBag.ShopID);

// Create a function that the hub can call back to alert new sales.

notifications.client.alertNewSalesToPage = function (shopid)
{
// check if sales happened for this shop then play notification

if (shopid == thisShopID) 
{

 var sound =new Howl({
          src: ['../sounds/rings.mp3','../sounds/rings.wav','../sounds/rings.ogg',
          '../sounds/rings.aiff'],
          autoplay: true,
          loop: true
          });

          sound.play();

          $('#loading').show();

          // Partial View to Update LatestSales for this Shop

          $("#new-Sales").load('@Url.Action("GetLatestSales", "Shop")')

          $('#loading').hide();

          console.log('New Sale happened, Notification Played');
        }

    };


    // Start the connection.
    $.connection.hub.start().done(function () {


        console.log('signalR connection started');


    }).fail(function (e) {
        alert(e);
    });
});



</script>

使用Howler.js插件播放通知,查看this帖子。

希望能帮助别人。

【讨论】:

    猜你喜欢
    • 2015-05-27
    • 2010-12-08
    • 2017-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-01
    • 2013-04-09
    相关资源
    最近更新 更多