[英]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.