ノードJsアプリケーションからSQL Serverに接続しようとすると、以下の問題が発生する。ノードjsアプリケーションからのSQL Server接続の問題
使用されるSQL Server名はDESKTOP-FCM7L54\SRINIVAS
です。
エラーの詳細:
{ ConnectionError: Failed to connect to DESKTOP-FCM7L54SRINIVAS:1433 - getaddrinfo ENOTFOUND DESKTOP-FCM7L54SRINIVAS
at Connection.base.ConnectionPool._poolCreate.base.Promise.tedious.once.err (C:\Users\Owner\documents\visual studio 2015\Projects\NodejsConsoleApp3\SqlNodejs\node_modules\mssql\lib\tedious.js:216:17)
at Connection.g (events.js:292:16)
at emitOne (events.js:96:13)
at Connection.emit (events.js:188:7)
at Connection.socketError (C:\Users\Owner\documents\visual studio 2015\Projects\NodejsConsoleApp3\SqlNodejs\node_modules\tedious\lib\connection.js:699:14)
at C:\Users\Owner\documents\visual studio 2015\Projects\NodejsConsoleApp3\SqlNodejs\node_modules\tedious\lib\connection.js:590:25
at C:\Users\Owner\documents\visual studio 2015\Projects\NodejsConsoleApp3\SqlNodejs\node_modules\tedious\lib\connector.js:68:18
at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:62:16)
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (dns.js:89:17)
Code: 'ESOCKET',
var express = require('express');
var app = express();
var sql = require("mssql");
// config for your database
var config = {
server: 'DESKTOP-FCM7L54\SRINIVAS',
database: 'Test',
user: 'sa',
password: 'test',
port: 1433
};
app.get('/', function (req, res) {
//connect to your database
sql.connect(config, function (err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
request.query('select * from Customer', function (err, recordset) {
if (err) console.log(err)
// send records as a response
res.send(recordset);
});
});
sql.close();
});
var server = app.listen(5000, function() {
console.log('Server is running..');
});