【问题标题】:Node JS Sequelize cannot connect to Azure SQL DatabaseNode JS Sequelize 无法连接到 Azure SQL 数据库
【发布时间】:2020-04-26 10:21:34
【问题描述】:

我目前正在尝试将 Node JS 应用程序连接到我使用 Azure SQL 数据库创建的单个数据库。为了连接到数据库,我使用 Sequelize。为了做到这一点,我设置了防火墙以接受我的 IP 地址,如 here 解释的那样,我像这样配置了一个 config.json 文件

"username": "SERVER_ADMIN_NAME@MY_IP_ADDRESS",
"password": "ADMIN_PASSWORD",
"database": "DATABASE_NAME",
"host": "SERVER_NAME",
"port": 1433,
"dialect": "mssql",
"dialectOptions": {
   "options": {
        "encrypt": true
    }
 }

但是,在运行应用程序后,它无法连接到数据库并返回以下消息

"Cannot open server '211' requested by the login. Client with IP address 'MY_IP_ADDRESS' is not allowed to access the server.  To enable access, use the Windows Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range.  It may take up to five minutes for this change to take effect."

我已经等了超过 5 分钟,但结果还是一样。现在,我首先想到的是我如何为 config.json 文件提供值。但是,在使用以下查询检查sys.database_firewall_rules

SELECT * FROM sys.database_firewall_rules;

桌子是EMPTY。从这里开始,我真的不确定我应该做什么。我想知道是否有人能指出我错过了什么?提前致谢!

【问题讨论】:

    标签: node.js azure sequelize.js azure-sql-database azure-sql-server


    【解决方案1】:

    您不应使用 IP 地址连接到 Azure SQL 数据库,因为它可以随时更改。

    您可以使用繁琐的驱动程序尝试如下连接吗?

    var Sql = require('sequelize');
    var sql = new Sql('dbname', 'UserName@server', 'password', {
      host: 'server.database.windows.net',
      dialect: 'mssql',
      driver: 'tedious',
      options: {
        encrypt: true,
        database: 'dbname'
      },
      port: 1433,
      pool: {
        max: 5,
        min: 0,
        idle: 10000
      }
    });
    

    确保将公共 IP 地址而不是本地 IP 地址添加到防火墙规则中。要验证您已添加的防火墙规则,请运行以下查询:

    SELECT * FROM sys.firewall_rules;
    

    上面的查询显示了服务器级别的规则。您已经在该级别创建了规则。

    【讨论】:

      猜你喜欢
      • 2018-10-03
      • 1970-01-01
      • 2019-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多