简体   繁体   English

错误:连接到 azure sql 时读取 ECONNRESET

[英]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,请按照此处的说明进行操作

but for Azure MySQL use this .但是对于 Azure MySQL 使用这个

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

相关问题 连接到 Azure SQL 数据库时,Databricks 作业出现频繁的“连接超时”错误 - Getting frequent "connection timeout" error on Databricks Job while connecting to Azure SQL Database 连接 Azure Data Studio 时出错,在带有 SQL 服务器的容器中使用 Docker - Error while connecting Azure Data Studio working with Docker in a container with SQL Server 连接到 Azure 时出现 SQL 登录失败错误 (18456) SQL - Getting SQL login failed error (18456) when connecting to Azure SQL 安全连接到 SQL Azure - Securely Connecting to SQL Azure 错误:14 不可用:在 gRPC 客户端连接中读取 ECONNRESET - Error: 14 UNAVAILABLE: read ECONNRESET in gRPC Client connection 从 Azure 数据工厂连接到 SQL Db 时出错 - Error connecting to SQL Db from Azure Data Factory Firebase 托管错误:服务器错误。 读取 ECONNRESET - Firebase hosting Error: Server Error. read ECONNRESET 使用 logstash 连接 MYSQL 时出错 - Error while connecting MYSQL with logstash 使用 SQL 服务器代理连接 VM 上的 SQL 服务器实例时出现 Sqlcmd 错误 - Sqlcmd error while connecting with SQL Server instance on a VM using SQL Server proxy Synapse Notebook 在连接到 AWS RDS SQL 服务器时抛出超时错误 - Synapse Notebook throws timeout error while connecting to AWS RDS SQL Server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM