gpt4 book ai didi

sql-server - Azure SQL Server 错误此版本的 SQL Server 不支持语句 'RECEIVE MSG'

转载 作者:行者123 更新时间:2023-12-03 00:32:30 25 4
gpt4 key购买 nike

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

它在本地主机上运行良好。但是上传到Azure服务器后,此方法会抛出以下错误:

Message":"An error has occurred.","ExceptionMessage":"Statement 'RECEIVE MSG' is not supported in this version of SQL Server.","ExceptionType":"System.Data.SqlClient.SqlException","StackTrace":" \r\nServer stack trace: \r\n at System.Data.SqlClient.SqlConnection.OnError(SqlException exception , Boolean breakConnection, Action`1 wrapCloseInAction)

可能是什么问题?

最佳答案

实际上,您的 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。

关于sql-server - Azure SQL Server 错误此版本的 SQL Server 不支持语句 'RECEIVE MSG',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33693020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com