【问题标题】:not able to connect to Azure SQL DB using nodeJS无法使用 nodeJS 连接到 Azure SQL DB
【发布时间】:2021-12-17 08:09:03
【问题描述】:
const azureConfig = {
    authentication: {
      options: {
        userName: "user@server.com", 
        password: "xyz" 
      },
      type: "default"
    },
    server: "myApp.database.windows.net", 
    options: {
      database: "MYDB", //update me
      encrypt: true,
      port: 1433
    }
  };

const connectToAzure = () => {
    const connection = new Connection(azureConfig);
    connection.on("connect", err => {
    if (err) {
        console.error(err.message);
        throw err;
    } else {
       // query database code goes here
    }
    });

    connection.connect();
};
connectToAzure();

我收到一个错误 无法打开登录请求的服务器“user.server.com”。登录失败 如何解决?

【问题讨论】:

  • 使用 Azure SQL,如果您无法通过防火墙,通常会看到这种情况。您无需指定此连接是来自某个服务器、Web 应用程序还是您的本地计算机,但您可以转到 Azure 门户和create a firewall rule 以允许访问。

标签: javascript node.js azure


【解决方案1】:

感谢@mherzig,提供此doc 链接。

您必须在门户中设置防火墙规则以允许访问 Azure SQL-db 连接。

如果您的连接来自互联网,您可以参考此link

-或-

如果您的连接来自 Azure 内部,则通过将允许 Azure 服务和资源访问此服务器切换为 开启,直接从 Azure 门户刀片打开防火墙和虚拟网络设置中。

【讨论】:

  • 我建议鼓励其他人将他们的 cmets 扩展为完整的答案,而不是反复将其他人的内容重新用作您自己的内容。这不是您第一次接受别人的评论并将其变成您自己的答案。
猜你喜欢
  • 2019-03-30
  • 1970-01-01
  • 2018-01-05
  • 2021-09-19
  • 2013-11-27
  • 1970-01-01
  • 1970-01-01
  • 2023-03-12
  • 2016-07-16
相关资源
最近更新 更多