tedious: NTLM: "Login failed for user XXXXXX" but can log in using MSSQL SMS and .Net's SqlClient
Hello everyone.
I’m not sure why this is happening. The following script fails when attempting to use a specific domain account which has access to the database named in the “database” config attribute.
I’m running the script from the command-line which I launched under the same account which needs to access the database.
I can connect using this account’s credentials to MSSQL Management Studio (and can access said database) and I can also access it using these credentials using MS SqlClient.
Finally, if I switch the credentials in this script to my own and run the script under my own account, it works as expected.
The only imaginable variable I can think of is that the “real” user name has a space in it (I didn’t create it, my central security team did so I have zero control over that). It’s something like “XY-SQL-APP RW”. I doubt that has anything to do with it but just throwing it out there.
The exact error I’m getting is "ConnectionError: Login failed for user ‘DOMAIN\XT-SQL-APP RW’. The full error appears after the code.
I’m bummed because if I can’t get this to work I’m going to have to build this application in .Net when the rest of the application is Javascript (Vue.js & Node). This particular application was to be an API.
var Connection = require("tedious").Connection;
var Request = require("tedious").Request;
var TYPES = require("tedious").TYPES;
("use strict");
var config = {
server: "SERVER",
authentication: {
type: "ntlm",
options: {
domain: "DOMAIN",
userName: "xxxxxxxx,
password: "xxxxxxxx",
intanceName: "INSTANCENAME"
}
},
options: {
database: "DBNAME",
trustServerCertificate: true,
encrypt: true
}
};
var cn = new Connection(config);
console.log(cn.config.authentication.options);
cn.on("connect", err => {
if (err) {
console.log(err);
} else {
console.log("CONNECTED");
}
});
Full error message:
{ ConnectionError: Login failed for user 'PERS\XT-SQL-APP RW'.
at ConnectionError (c:\Projects\apis\b50api\node_modules\tedious\lib\errors.js:13:12)
at Parser.tokenStreamParser.on.token (c:\Projects\apis\b50api\node_modules\tedious\lib\connection.js:853:51)
at emitOne (events.js:116:13)
at Parser.emit (events.js:211:7)
at Parser.parser.on.token (c:\Projects\apis\b50api\node_modules\tedious\lib\token\token-stream-parser.js:37:14)
at emitOne (events.js:116:13)
at Parser.emit (events.js:211:7)
at addChunk (c:\Projects\apis\b50api\node_modules\readable-stream\lib\_stream_readable.js:298:12)
at readableAddChunk (c:\Projects\apis\b50api\node_modules\readable-stream\lib\_stream_readable.js:280:11)
at Parser.Readable.push (c:\Projects\apis\b50api\node_modules\readable-stream\lib\_stream_readable.js:241:10)
message: 'Login failed for user \'PERS\\XT-SQL-APP RW\'.',
code: 'ELOGIN' }
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 17 (8 by maintainers)
I followed the steps in this answer https://stackoverflow.com/a/12774856/1655756 and it solved my issue.