gpt4 book ai didi

c# - 有什么方法可以对 Azure SQL 数据库更改使用react吗?

转载 作者:行者123 更新时间:2023-12-03 01:39:24 25 4
gpt4 key购买 nike

我在应用程序中使用 SignalR 并对我使用 Sql 依赖项的数据库更改使用react

SqlDependency.Start(con);

但我收到以下错误:

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

据我了解,Azure SQL 数据库不支持 Service Broker。

除了迁移到Azure VM之外还有什么解决方案吗?

具有 SQL 依赖关系的代码示例:

public class NotificationComponent
{
public void RegisterNotification(DateTime currentTime)
{
string conStr = ConfigurationManager.ConnectionStrings["sqlConString"].ConnectionString;
string sqlCommand = @"SELECT [ContactID],[ContactName],[ContactNo] from [dbo].[Contacts] where [AddedOn] > @AddedOn";
using (SqlConnection con = new SqlConnection(conStr))
{
SqlCommand cmd = new SqlCommand(sqlCommand, con);
cmd.Parameters.AddWithValue("@AddedOn", currentTime);
if (con.State != System.Data.ConnectionState.Open)
{
con.Open();
}
cmd.Notification = null;
SqlDependency sqlDep = new SqlDependency(cmd);
sqlDep.OnChange += sqlDep_OnChange;
using (SqlDataReader reader = cmd.ExecuteReader())
{

}
}
}

void sqlDep_OnChange(object sender, SqlNotificationEventArgs e)
{
if (e.Type == SqlNotificationType.Change)
{
SqlDependency sqlDep = sender as SqlDependency;
sqlDep.OnChange -= sqlDep_OnChange;

var notificationHub = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
notificationHub.Clients.All.notify("added");
RegisterNotification(DateTime.Now);
}
}

public List<Contact> GetContacts(DateTime afterDate)
{
using (MyPushNotificationEntities dc = new MyPushNotificationEntities())
{
return dc.Contacts.Where(a => a.AddedOn > afterDate).OrderByDescending(a => a.AddedOn).ToList();
}
}
}

最佳答案

您可以使用 Azure 逻辑应用中 SQL 的“创建项目时”和“修改项目时”触发器来对数据更改使用react。

Azure 逻辑应用中的 SQL 连接器使用轮询机制通过 TIMESTAMP/ROWVERSION 列查询表中的更改。这种数据类型是专门为 SQL 中的此类处理而设计的。轮询查询实质上选择 rowversion 大于上次轮询值的所有行。该行为是可靠的,因为该列由 SQL Server 控制,并且在没有新数据的情况下性能非常快。当有新数据时,性能与简单的行查询相当。

更多信息请阅读this文章。

关于c# - 有什么方法可以对 Azure SQL 数据库更改使用react吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55338264/

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