在Azure中使用SQL依赖关系

以赛亚·奥罗斯科·托莱多

在我的本地数据库中,Sql Dependency工作正常,但是当我迁移到Azure数据库时无法正常工作。

我检查服务代理是否已启用并已激活。

这是错误:

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

这是我的代码:

     public class Program
  {
    static void Main(string[] args)
    {
      SqlClientPermission permission = new SqlClientPermission(System.Security.Permissions.PermissionState.Unrestricted);

      if (SolicitarNotifications())
      {
        string con = "Server=tcp:xxxxx.database.windows.net,0000;Initial Catalog=TestSQLDependendcy;Persist Security Info=False;User ID=xxxx;Password=xxxxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";
        SqlConnection conn = new SqlConnection(con);
        SqlDependency.Start(con);
        Console.WriteLine("Empezando a escuchar");
        GetAlerts();

        Console.WriteLine("Presiona enter para salir");
        Console.ReadLine();

        Console.WriteLine("Deteniendo la escucha...");
        SqlDependency.Stop(con);
      }
      else {
        Console.WriteLine("No tienes permitido solicitar notificaciones");
      }
    }

    public static void GetAlerts()
    {
      try
      {
        using (SqlConnection con = new SqlConnection("Server=tcp:xxxxx.database.windows.net,0000;Initial Catalog=TestSQLDependendcy;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"))
        {
          SqlCommand cmd = new SqlCommand("Select Correo, Nombre From TestNombre", con);
          cmd.CommandType = CommandType.Text;
          cmd.Notification = null;
          cmd.Dispose();
          SqlDependency dependency = new SqlDependency(cmd);
          dependency.OnChange += new OnChangeEventHandler(OnDataChange);
          con.Open();
          SqlDataReader dr = cmd.ExecuteReader();
          {
            while (dr.Read())
            {
              if (dr.HasRows)
              {
                using (MailMessage mm = new MailMessage())
                {
                      //Send Mails
                }
              }
            }
          }
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.Message.ToString());
      }
    }

    private static void OnDataChange(object sender, SqlNotificationEventArgs e)
    {

      SqlDependency dependency = sender as SqlDependency;
      dependency.OnChange -= new OnChangeEventHandler(OnDataChange);
      GetAlerts();
    }
  }

如何在Azure SQL数据库中运行此服务?

埃文德罗·保拉(Evandro Paula)

当前,Azure SQL不支持Service Broker。

https://docs.microsoft.com/zh-cn/sql/t-sql/statements/receive-transact-sql?view=sql-server-2017上找到RECEIVE语句支持的版本,该声明指出Azure SQL不支持它。 。

此外,该文档https://docs.microsoft.com/zh-cn/azure/sql-database/sql-database-features提供了SQL Server,Azure SQL和托管实例之间的出色功能比较文档。请注意,管理实例在某些方面支持Service Broker。我建议注册并尝试一下。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Java中使用Maven解决依赖关系

在库中使用外部依赖关系

在 azure dev-ops 管道 maven 任务中使用设置文件来解决依赖关系

使用存储过程的SQL依赖关系

在python stanfordnlp中使用Stanford依赖关系(而不是通用依赖关系)

如何在Maven的ProjectB中使用ProjectA的依赖关系?

如何在SBT的.scala文件中使用外部依赖关系?

如何在SpringBoot中使用Lambok依赖关系?

在与Windsor的依赖关系中使用相同的参数值

对于azure-mgmt-redis maven依赖关系使用什么?

如何在关系SQL查询中使用NOT

使用工件的依赖关系

使用Unity解决依赖关系

使用依赖关系构建Maven

使用 NestJS 解决依赖关系

在Circe中使用没有显式Configuration依赖关系的蛇形案例

如何在TestNG测试用例中使用Governor注入依赖关系?

Maven库在具有不同依赖关系的更多项目中使用

如何在测试中使用gradle功能变量依赖关系?

Gradle在编译任务中使用具有依赖关系的jar

如何在Entity Framework Core中使用循环依赖关系正确播种数据?

无法在Android中使用Selenium依赖关系(在纯Java中有效)

如何在useEffect中使用变量而不将它们置于依赖关系中?

Stack:如何在Setup.hs中使用多包依赖关系?

如何在命令行中使用带有gradle的袜子来解决依赖关系?

我可以在Python中使用NLTK从Spacy依赖关系树中找到主题吗?

如何在多个项目中使用简单注入器并通过传递来解决依赖关系

如何在Django Zappa项目中使用非Python依赖关系?

尽管我在DESCRIPTION中使用了导入,但命名空间依赖关系不是必需的错误