sql-server - 无法使用 Tedious 和 Node JS 连接到本地 SQL Server 数据库

标签 sql-server node.js tedious

我正在尝试连接到本地计算机上的 SQL Server。我正在尝试使用乏味和乏味的 ntlm。两者的配置如下:

var tds = require("tedious-ntlm");
//var tds = require("tedious");
var config = {
userName: 'pratikdb',
password: 'pratikdb',
server: '.',
options: {
    database: "TEST",
    debug: {
        packet: false,
        payload: false,
        token: false,
        data: false
    },
    encrypt: true
  }
};


http.createServer(app).listen(app.get('port'), function () {
    console.log('Express server listening on port ' + app.get('port'));
    var connection = new tds.Connection(config);
    connection.on('connect', function (err) {
        console.log(err);
    });
});

当我使用 tedious 时,我得到了这个错误:

ConnectionError: Failed to connect to .:1433 - getaddrinfo ENOTFOUND . .:1433]
message: 'Failed to connect to .:1433 - getaddrinfo ENOTFOUND . .:1433', code: 'ESOCKET'

当我使用“tedious-ntlm”时,出现此错误:

Connection to .:1433 - failed Error: getaddrinfo ENOTFOUND . .:1433

如前所述here ,即使我遇到同样的错误,我也尝试使用机器的 ip。

编辑:

当我按照@jmugz3 的建议修改如下配置时:

var config = {
    userName: 'pratikdb',
    password: 'pratikdb',
    server: 'DELL',
    options: {
        instanceName: ".",
        database: "TEST",
        debug: {
            packet: false,
            payload: false,
            token: false,
            data: false
        },
        encrypt: true
    }
};

我收到错误:

Error: Port for . not found in ServerName;DELL;InstanceName;MSSQLSERVER;IsClustered;No;Version;11.0.2100.60;tcp;1433;np;\DELL\pipe\sql\query;;

谁能帮帮我?

提前致谢。

最佳答案

找到答案 tedious discussion .将我的配置变量更改为

var sqlConfig = {
    userName: 'pratikdb', //username created from SQL Management Studio
    password: 'pratikdb',
    server: 'DELL',    //the IP of the machine where SQL Server runs

    options: {
        instanceName: 'MSSQLSERVER',
        database: 'Test',  //the username above should have granted permissions in order to access this DB.
        debug: {
            packet: false,
            payload: false,
            token: false,
            data: false
        },
        //encrypt: true
    }

};

要查找的要点是 server 和 instanceName 的大写。出于某种原因,乏味的是保持数组的键和值的大小写敏感。

关于sql-server - 无法使用 Tedious 和 Node JS 连接到本地 SQL Server 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35967238/

相关文章:

node.js - 将 'virtual' 变量添加到 Mongoose 模式?

node.js - 如果 Node 服务器宕机了。如何在 socket.io 上进行错误处理

python - 刷新链接到nodeJS的python文件

sql-server - 在 Node 中验证来自 SQL Server 的证书

sql-server - 请求错误 : { message: 'Requests can only be made in the LoggedIn state, not the SentLogin7WithStandardLogin state' , 代码: 'EINVALIDSTATE' }

SQL Server 触发器更新另一个表的列

.net - 从 SQL XML 列中的元素获取属性名称

javascript - 无法使用 Node.js 和繁琐的连接到 SQL Server

sql - 将 UNION ALL 转换为 JOIN

SQL 查询更新输入参数不为 Null 的表列?