[英]Error: read ECONNRESET while connecting to azure sql
I've created and tested MySql scripts it works fine on localhost but when I try to connect to azure I get the following errors:我已经创建并测试了 MySql 脚本,它在本地主机上运行良好,但是当我尝试连接到 azure 时,出现以下错误:
var mysql = require("mysql");
const fs = require('fs');
var config = {
host: 'myhost',
database: 'mydb',
user: 'myusername',
password: 'mypass',
port: 1433,
ssl: {
rejectUnauthorized: true,
ca: fs.readFileSync("my path to ssl")
}
}
function initializeConnection(config) {
function addDisconnectHandler(connection) {
connection.on("error", function (error) {
if (error instanceof Error) {
if (error.code === "PROTOCOL_CONNECTION_LOST") {
console.error(error.stack);
console.log("Lost connection. Reconnecting...");
initializeConnection(connection.config);
} else if (error.fatal) {
error;
}
}
});
}
var connection = mysql.createConnection(config);
addDisconnectHandler(connection);
connection.connect(
function (err) {
if (err) {
console.log("!!! Cannot connect !!! Error:");
throw err;
}
else
{
console.log("Connection established.");
}
});
return connection;
}
var connection = initializeConnection(config);
module.exports.connection = connection;
But I get this error但我得到这个错误
errno: -4077,
code: 'ECONNRESET',
syscall: 'read',
fatal: true
I got the error because i mistook Azure SQL database connection implementation for Azure MySQL database connection, didn't knew that both where complete different service.我得到这个错误是因为我把 Azure SQL 数据库连接实现误认为是 Azure MySQL 数据库连接,不知道两者在哪里完成不同的服务。
For clarification: To connect to Azure SQL I have to use Tedious, follow the instruction here澄清一下:要连接到 Azure SQL 我必须使用 Tedious,请按照此处的说明进行操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.