I'm trying to connect to a Microsoft SQL Server using Knex.js, but I'm getting getaddrinfo ENOTFOUND. I'm aware that this is an indication, that NodeJS is unable to resolve the address, often through DNS or protocol problems.
const knex = require('knex')({
client: 'mssql',
connection: {
server: 'filesrv\\docx', // backslash in string needs to be escaped
user: 'user', // changed for privacy reasons
password: 'secret', // changed for privacy reasons
options: {
port: 1433,
database: 'DX_Matching_DB'
}
}
});
UnhandledPromiseRejectionWarning: ConnectionError: Failed to connect to filesrv\docx:1433 - getaddrinfo ENOTFOUND filesrv\docx
at ConnectionError(.\node_modules\tedious\lib\errors.js:13:12)
at Connection.socketError(.\node_modules\tedious \lib\connection.js:1664:56)
...
SQL Server in SQL Server Object Explorer:
App is run on Windows. Resolve-DnsName is able to resolve filesrv\docx. No change when exchanging filesrv for the corresponding IP.
CodePudding user response:
The knex configuration object uses the instance name inside the options, e.g.:
const knex = require('knex')({
client: 'mssql',
connection: {
server: 'filesrv',
user: 'user',
password: 'secret',
options: {
database: 'DX_Matching_DB',
instanceName: 'docx'
}
}
});