0

I am trying to connect to a LocalDB\MSSQLLocalDB SQLExpress instance in my Node.js application that uses Objection.js/Knex for the data layer.

When I try to run a migration it fails to connect to the database. But I can connect via SSMS without issue.

Here is my Knexfile.js connection settings

module.exports = {
    development: {
        client: 'mssql',
        useNullAsDefault: true,
        connection: {
            server: '(LocalDB)\\MSSQLLocalDB',
            user: 'localadmin',
            password: 'password$',
            database: 'database'
        },
        migrations: {
            directory: './migrations',
            tableName: 'knex_migrations'
        },
        seeds: {
            directory: './seeds'
        },
        ...knexSnakeCaseMappers()
    }
};

When I run a migration it gives the following error:

Failed to connect to (LocalDB)\MSSQLLocalDB:1433 - getaddrinfo ENOTFOUND (LocalDB)\MSSQLLocalDB
Error: Failed to connect to (LocalDB)\MSSQLLocalDB:1433 - getaddrinfo ENOTFOUND (LocalDB)\MSSQLLocalDB
    at Connection.socketError (D:\Code\backend\node_modules\tedious\lib\connection.js:1393:28)
    at D:\Code\backend\node_modules\tedious\lib\connection.js:1153:21
    at GetAddrInfoReqWrap.callback (D:\Code\backend\node_modules\tedious\lib\connector.js:195:16)
    at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:77:17)

I believe this is an issue with tcp/ip settings in SqlExpress but I cannot find an easy way to change those.

Is there any settings for the Knexfile that will allow for a SQLExpress database connection?

A. Hasemeyer
  • 1,452
  • 1
  • 18
  • 47

1 Answers1

0

LocalDB only accepts named pipes connections. Use proper SQL Express and enable TCP connections

ErikEJ
  • 40,951
  • 5
  • 75
  • 115