NodeJS 连接到 SQL 服务器 getaddrinfo ENOTFOUNT

NodeJS connect to SQL Server getaddrinfo ENOTFOUNT

我正在尝试使用 Knex.js 连接到 Microsoft SQL 服务器,但我收到 getaddrinfo ENOTFOUND。我知道这表明 NodeJS 无法解析地址,通常是通过 DNS 或协议问题。

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 SQL 服务器对象资源管理器中的服务器:

应用 运行 Windows。 Resolve-DnsName 能够解析 filesrv\docx。为相应IP交换filesrv时无变化

knex 配置对象使用选项中的实例名称,例如:

const knex = require('knex')({
    client: 'mssql',
    connection: {
        server: 'filesrv',
        user: 'user',
        password: 'secret',
        options: {
            database: 'DX_Matching_DB',
            instanceName: 'docx'
        }
    }
});