Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to connect to Mssql server via knex

I'm trying to connect to a remote database with knex but I get this error: "tedious deprecated The default value for options.encrypt will change from false to true. Please pass false explicitly if you want to retain current behaviour. at node_modules\mssql\lib\tedious.js:212:23 Unhandled rejection ConnectionError: Failed to connect to 151.80.119.227,14831:1433 - getaddrinfo ENOTFOUND 151.80.119.227,14831"

I can connect via Microsoft sql server management studio with same host, user, password so I'm lost.

Edit: This is how I create my knex var:

 var knex = require('knex')({
  client: 'mssql',
  connection: {
    server : '151.80.119.227,14831',
    user : '****',
    password : '****',
    database : '****'
  }
});

I can connect to it via python with:

 con = pyodbc.connect("DRIVER={SQL Server};server=151.80.119.227,14831;database=*****;uid=****;pwd=****")

So why won't it connect through node.js ....

like image 791
JohnDoe Avatar asked Jan 02 '23 06:01

JohnDoe


1 Answers

Port should actually be specified in the MSSQL options variable:

 var knex = require('knex')({
  client: 'mssql',
  connection: {
    server : '151.80.119.227',
    user : '****',
    password : '****',
    database : '****',
    options: {
      port: 14831
    }
  }
});

This is from reading the code at https://github.com/tgriesser/knex/blob/v0.16.2/src/dialects/mssql/index.js

like image 90
josh64 Avatar answered Jan 05 '23 15:01

josh64