Azure SQL Server错误此版本的SQL Server不支持语句“RECEIVE MSG”

时间:2015-11-13 12:42:05

标签: sql-server azure sqldependency

我已经使用SQLdependency和SignalR向用户显示警报..代码如下:

public IEnumerable<AlertInfo> GetData(long UserId)
{
    using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["yafnet"].ConnectionString))
    {
        connection.Open();
        using (SqlCommand command = new SqlCommand(@"SELECT [AlertID],[AlertNote],[AlertDetails],[AlertDate],[Location]
      FROM [dbo].[Alerts] where [UserID]=" + UserId + " AND [IsViewed]=0", connection))
        {
            // Make sure the command object does not already have
            // a notification object associated with it.
            command.Notification = null;
            SqlDependency.Stop(ConfigurationManager.ConnectionStrings["yafnet"].ConnectionString);
            SqlDependency.Start(ConfigurationManager.ConnectionStrings["yafnet"].ConnectionString);

            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>()
                    .Select(x => new AlertInfo()
                    {
                        AlertID = x.GetInt64(0),
                        AlertNote = x.GetString(1),
                        AlertDetails = x.GetString(2),
                        AlertDate = x.GetDateTime(3),
                        Location = x.GetString(4)
                    }).ToList();
        }
    }
}

它在localhost上工作正常。但上传到Azure服务器后,此方法会引发以下错误:

  

消息“:”发生错误。“,”ExceptionMessage“:”语句'RECEIVE MSG'不受支持    在此版本的SQL Server中。“,”ExceptionType“:”System.Data.SqlClient.SqlException“,”StackTrace“:”   \ r \ n服务器堆栈跟踪:\ r \ n在System.Data.SqlClient.SqlConnection.OnError(SqlException异常)   ,Boolean breakConnection,Action`1 wrapCloseInAction)

可能是什么问题?

1 个答案:

答案 0 :(得分:0)

实际上您的SQL Server数据库必须有is_broker_enabled = 1。 您需要检查它是否已启用。

要验证这一点,请使用命令SELECT name, is_broker_enabled FROM sys.databases。 如果您的数据库显示结果为“1”,则表示没有问题,如果为“0”,则必须使用此命令ALTER DATABASE yourdb SET ENABLE_BROKER启用它。

但坏消息是Azure SQL数据库显示已启用但不再支持is_broker_enabled

为此,您需要将完整的SQL Server实例安装到Azure VM。