简体   繁体   English

ConnectionError:无法连接到MyServer:1433

[英]ConnectionError: Failed to connect to MyServer:1433

I'm trying to connect to a remote SQL Server from my machine, I'm working with node. 我正在尝试从计算机连接到远程SQL Server,正在使用节点。 I can connect to it through SQL Management Studio, and I could connect with a C# application as well (both using Windows Authentication). 我可以通过SQL Management Studio连接到它,也可以与C#应用程序连接(都使用Windows身份验证)。 I've already searched in several forums (in some questions here as well) and couldn't find a solution. 我已经在几个论坛中搜索过(这里也有一些问题),找不到解决方案。

Below you can find the error I got: 在下面,您可以找到我得到的错误:

   message: 'Failed to connect to MyServer:1433 - getaddrinfo ENOTFOUND MyServer',
     code: 'ESOCKET' },
  name: 'ConnectionError' }

This is the code I'm using: 这是我正在使用的代码:

'use strict';
var http = require('http');
var express = require('express');
var port = process.env.PORT || 1337;

var app = express();

app.get('/', (req, resp) => {
    var sql = require("mssql");

    var config = {
        driver: 'msnodesqlv8',
        server: 'MyServer/Instance',
        database: 'MyDB',
        options: {
            trustedConnection: true
        }
    };

    sql.connect(config, (error) => {
        if (error)
            console.log(error);

        var request = new sql.Request();
        request.query('select * from MyTable', (err, recordset) => {
            if (err)
                console.log(err);

            resp.send(recordset);
        });

    });

});

var servidor = app.listen(port, function () {
    console.log("Server running");
});

I looked other questions ( here and here for example), but no luck. 我看了其他问题(例如在这里这里 ),但是没有运气。

I got resolve this problem. 我已经解决了这个问题。 First of all I created an user on my db and after include in my config the user and password. 首先,我在数据库上创建了一个用户,然后在配置中包含了用户名和密码。 I needed to specify the instance and db in options, cause node was not recognizing when put all in the same string. 我需要在选项中指定实例和数据库,因为将所有节点放在同一字符串中时节点无法识别。

var config = {
    user: 'user_name',
    password: '****',
    server: 'MyServer',
    options: {
        instance: 'MyInstance',
        database: 'MyDB'
    }
};

暂无
暂无

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

相关问题 Node.js MSSQL tedius ConnectionError: Failed to connect to localhost:1433 - connect ECONNREFUSED - Node.js MSSQL tedius ConnectionError: Failed to connect to localhost:1433 - connect ECONNREFUSED ConnectionError [SequelizeConnectionError]:无法连接到:1433 - 无法连接(序列)本地机器 window 10 - ConnectionError [SequelizeConnectionError]: Failed to connect to :1433 - Could not connect (sequence) local machine window 10 错误:无法连接到本地主机:1433 - 连接 ECONNREFUSED 127.0.0.1:1433 docker - Error: Failed to connect to localhost:1433 - connect ECONNREFUSED 127.0.0.1:1433 docker ConnectionError:无法连接到 <SQLServerDB> -连接EACCES <SQLServerDB> - ConnectionError: Failed to connect to <SQLServerDB> - connect EACCES <SQLServerDB> [连接错误:15000 毫秒内无法连接到 IP] - [ConnectionError: Failed to connect to IP in 15000ms] ConnectionError:无法连接到{数据库服务器}-无法连接(顺序) - ConnectionError: Failed to connect to {database server} - Could not connect (sequence) ConnectionError:无法连接到localhost:15000ms内未定义 - ConnectionError: Failed to connect to localhost:undefined in 15000ms telnet 本地主机 1433 失败 - telnet localhost 1433 failed 无法在 15000 毫秒内连接到 mydb.database.windows.net:1433(Microsoft Azure SQL 数据库) - Failed to connect to mydb.database.windows.net:1433 in 15000ms (Microsoft Azure SQL Database) 使用 sequelize-automate 出现错误“ConnectionError [SequelizeConnectionError]:无法连接到 localhost:1443 - 无法连接(序列)” - Error "ConnectionError [SequelizeConnectionError]: Failed to connect to localhost:1443 - Could not connect (sequence)" using sequelize-automate
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM