简体   繁体   English

无法在 15000 毫秒内连接到 mydb.database.windows.net:1433(Microsoft Azure SQL 数据库)

[英]Failed to connect to mydb.database.windows.net:1433 in 15000ms (Microsoft Azure SQL Database)

I am able to retrieve data from Microsoft Azure SQL Database using below code: -我可以使用以下代码从Microsoft Azure SQL Database中检索数据:-

const sql = require("mssql");

var config = {
  user: "user_name",
  password: "Pass@1234",
  server: "mydb.database.windows.net",
  database: "db_name",
  options: {
    enableArithAbort: true,
  },
  stream: true,
};

module.exports = function getQueryResult(query) {
  return new Promise((res, rej) => {
    sql.connect(config).then((pool) => {
      pool.query(query, (err, result) => {
        if (err) rej(err);
        res(result);
      });
    });
  });
};

I am using getQueryResult function to get the data from database.我正在使用getQueryResult function 从数据库中获取数据。

Everything is going perfect accept the thing that the below errors occurs in between.一切都很顺利,接受介于两者之间的以下错误。

  • Failed to connect to mydb.database.windows.net:1433 in 15000ms (Microsoft Azure SQL Database)

  • ConnectionError: Failed to connect to mydb.database.windows.net:1433 read ECONNRESET

  • ConnectionError: Failed to connect to mydb.database.windows.net:1433 socket hang up

I know this question has been asked before.我知道以前有人问过这个问题。 But I have tried all the solutions.但我已经尝试了所有解决方案。 None of the solution was specifically for Microsoft Azure SQL Database so I thought might be there is some problem in database.没有一个解决方案专门针对Microsoft Azure SQL Database ,所以我认为数据库中可能存在问题。

Thanks in advance.提前致谢。

Your code is a bit different from mine, my options is enclosed in double quotes.您的代码与我的代码有些不同,我的options用双引号括起来。 You also can download my sample code , it works for me, I have test it.你也可以下载我的示例代码,它对我有用,我已经测试过了。

Tips:提示:

You need set the rule of Firewalls .您需要设置Firewalls规则。 Make sure your local or webapp can access dbserver.确保您的本地或 webapp 可以访问 dbserver。

在此处输入图像描述

My code:我的代码:

const sql = require('mssql')
const config = {
    user: 'username',
    password: 'pwd',
    server: '***sqlserver.database.windows.net', // You can use 'localhost\\instance' to connect to named instance
    database: 'yourdb',
    "options": {
        "encrypt": true,
        "enableArithAbort": true
    }
}

const poolPromise = new sql.ConnectionPool(config)
  .connect()
  .then(pool => {
    console.log('Connected to MSSQL')
    return pool
  })
  .catch(err => console.log('Database Connection Failed! Bad Config: ', err))

module.exports = {
  sql, poolPromise
}

暂无
暂无

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

相关问题 [连接错误:15000 毫秒内无法连接到 IP] - [ConnectionError: Failed to connect to IP in 15000ms] ConnectionError:无法连接到localhost:15000ms内未定义 - ConnectionError: Failed to connect to localhost:undefined in 15000ms 连接到 SQL 服务器时出现超时错误:连接错误:无法在 15000 毫秒内连接到 servername\instancename - Timeout error while connecting to SQL Server: Connection Error: Failed to connect to servername\instancename in 15000ms 如何解决“ConnectionError:无法连接到<server> :<port> 在 15000 毫秒内”错误? - How do I fix the "ConnectionError: failed to connect to <server>:<port> in 15000ms" error? 天蓝色的移动服务调用sql服务器存储过程并获得requestTimeout 15000ms错误 - azure mobile services calling sql server stored procedure and get a requestTimeout 15000ms error 系列请求错误:SqlContext 错误。 步骤“GetData”失败:“超时:请求未能在 15000 毫秒内完成 - seriate RequestError: SqlContext Error. Failed on step “GetData” with: "Timeout: Request failed to complete in 15000ms ConnectionError:无法连接到MyServer:1433 - ConnectionError: Failed to connect to MyServer:1433 无法连接到 MFQ:1433 nodejs - Failed to connect to MFQ:1433 nodejs 无法连接到本地主机:1433-连接ECONNREFUSED 127.0.0.1:1433 - Failed to connect to localhost:1433 - connect ECONNREFUSED 127.0.0.1:1433 节点使用 Azure MS SQL 数据库从路由写入和读取数据 - Node write & read data with Azure MS SQL database from routes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM