Failed to connect to local SQL Server database using Tedious and Node JS
我正在尝试连接到本地计算机上的SQL Server。 我正在尝试使用乏味和乏味的ntlm。 两者的配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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); }); }); |
当我工作乏味时,会出现以下错误:
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
如此处所述,即使遇到相同错误,我也尝试使用机器的ip。
编辑:
当我按照@ jmugz3的建议如下修改配置时:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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;;
谁能帮帮我吗?
提前致谢。
找到了一个乏味的答案。 将我的配置变量更改为
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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 } }; |
要寻找的主要要点是服务器和instanceName的大写。 由于某种原因,单调乏味的是在数组的键和值上都保持区分大小写。