knex
uses mssql
which in turn uses either tedious
or msnodesqlv8
. tedious
doesn't support Windows Authentication. The default is tedious
. Trying to use tedious
with Windows Authentication results in ... Login failed for user ''.
. The full error message is :
(node:16568) UnhandledPromiseRejectionWarning: ConnectionError: Login failed for user ''.
at Connection.<anonymous> (K:\testprojects\nodesql\node_modules\mssql\lib\tedious.js:244:17)
at Object.onceWrapper (events.js:291:20)
at Connection.emit (events.js:203:13)
at Connection.processLogin7Response (K:\testprojects\nodesql\node_modules\mssql\node_modules\tedious\lib\connection.js:1397:14)
at Connection.message (K:\testprojects\nodesql\node_modules\mssql\node_modules\tedious\lib\connection.js:1932:14)
at Connection.dispatchEvent (K:\testprojects\nodesql\node_modules\mssql\node_modules\tedious\lib\connection.js:1084:36)
at MessageIO.<anonymous> (K:\testprojects\nodesql\node_modules\mssql\node_modules\tedious\lib\connection.js:984:14)
at MessageIO.emit (events.js:203:13)
at Message.<anonymous> (K:\testprojects\nodesql\node_modules\mssql\node_modules\tedious\lib\message-io.js:32:14)
at Message.emit (events.js:208:15)
Which clearly shows that the source is tedious
.
To get this I used this snippet :
const sql = require("mssql");
const config = {
database: "Master",
server: "myserver",
options: {
trustedConnection: true
}
};
(async () => {
await sql.connect(config)
const result = await sql.query`select name from sys.databases`
console.dir(result)
})()
The docs explain that you need to use const sql = require("mssql/msnodesqlv8");
to use msnodesqlv8
, eg :
const sql = require("mssql");
const config = {
database: "Master",
server: "myserver",
options: {
trustedConnection: true
}
};
After this change the query runs and produces a list of database names
Unfortunately, this won't help with knex
, as it loads and uses tedious
directly. Despite what the code comment says, msnodesqlv8 is actively maintained and had a release only 4 days ago.
knex
couldn't get the account's token, there would be a different error. You can check SQL Server's error log from SSMS to see what happened, and what the reason was for the failure. BTW is the exact messageLogin failed for user ''
or did you remove the account name? – Ladleknex
usesmssql
which in turn uses eithertedious
ormsnodesqlv8
. You could use one of the two drivers directly to see whether they can connect or not. It's one of those that's responsible for actually connecting. This way you can isolate the problem and check whether there's a known bug or an updated version – Ladleknex
has a hard dependency ontedious
which doesn't allow Windows Authentication – Ladle