node.jsadonis.jstedioustediousjs

How to use mssql connection using ip/instance?


I'm trying to connect to a production SQL Server instance but it fails to connect.

Could anyone help?

I'm grateful for the community's attention.

.env:

MSSQL_SERVER=ip/instance
MSSQL_PORT=1433
MSSQL_USER=sa
MSSQL_PASSWORD=password
MSSQL_DB_NAME=database

Error:

Failed to connect to ip/instance:1433 - getaddrinfo
ENOTFOUND ip/instance

adonisjs@lucid

mssql: {
      client: "mssql",
      connection: {
        user: Env.get("MSSQL_USER"),
        port: parseInt(Env.get("MSSQL_PORT")),
        server: Env.get("MSSQL_SERVER"),
        password: Env.get("MSSQL_PASSWORD", ""),
        database: Env.get("MSSQL_DB_NAME")
      },
      healthCheck: false,
      debug: false,
    },

Code:

Database.connection('mssql').from('dbo.EMP').select('*')

Solution

  • Thank you. Its work with -

    options: { encrypt: false, // for azure trustServerCertificate: true, // change to true for local dev / self-signed certs