简体   繁体   English

无法使用 nodeJS 连接到 Azure SQL DB

[英]not able to connect to Azure SQL DB using nodeJS

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();

I get an error Cannot open server "user.server.com" requested by the login.我收到错误无法打开登录请求的服务器“user.server.com”。 The login failed How to resolve it?登录失败如何解决?

Thanks @mherzig, for this doc link.感谢 @mherzig,提供此文档链接。

You have to set the firewall rules in the portal to allow access to the azure SQL-db connection.您必须在门户中设置防火墙规则以允许访问 azure SQL-db 连接。

If your Connections are from the internet, you can refer this link .如果您的连接来自互联网,您可以参考此链接

-OR- -或者-

If your Connections are from inside Azure , turn on directly from the Azure portal blade by switching the Allow Azure Services and resources to access this server to ON in the Firewalls and virtual networks settings.如果您的连接来自 Azure 内部,请直接从 Azure 门户边栏选项卡打开,方法是将防火墙和虚拟网络设置中的允许 Azure 服务和资源访问此服务器切换为开启

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM