Connect to SQL Server with mssql for node.js

user3209808 picture user3209808 · Jan 18, 2014 · Viewed 26.6k times · Source

I got a error message when I connect to SQL Server with mssql module for node.js.

[Error: connection to 192.168.1.101\sql:1433 - failed Error: getaddrinfo ENOENT]

var config = {
    //driver: 'msnodesql',
    user: '...',
    password: '...',
    server: '192.168.1.101\\sql',
    //TCP/IP 127.0.0.1
    database: 'ACCOUNTDB'
};

Answer

Patrik Šimek picture Patrik Šimek · Jan 25, 2014

You should be able to connect to named instance when using tedious driver with this config:

var config = {
    user: '...',
    password: '...',
    server: '192.168.1.101',
    driver: 'tedious',
    database: 'ACCOUNTDB',
    options: {
        instanceName: 'sql'
    }
};

Documentation also says:

The SQL Server Browser service must be running on the database server, and UDP port 1444 on the database server must be reachable.

Config for msnodesql driver is little more complicated because it's connection string doesn't support named instances by default (should change in future):

var config = {
    user: '...',
    password: '...',
    server: '192.168.1.101',
    driver: 'msnodesql',
    database: 'ACCOUNTDB',
    connectionString: "Driver={SQL Server Native Client 11.0};Server=#{server}\\sql;Database=#{database};Uid=#{user};Pwd=#{password};"
};