问题
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 ....
回答1:
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
回答2:
port for node-mssql driver should be set like this:
{
dialect: 'mssql',
connection: {
user: "sa",
password: "S0meVeryHardPassword",
server: "151.80.119.227",
port: 14831,
database: "knex_test"
}
}
来源:https://stackoverflow.com/questions/50857977/trying-to-connect-to-mssql-server-via-knex