1

I am trying to connect to a MS SQL Server database from my NodeJS server application and while it works flawlessly on my local machine using localhost/127.0.0.1 when I push it to a real server I get an Auth error.

The error I am getting is as follows:

The login is from an untrusted domain and cannot be used with Windows authentication

So I am thinking that maybe its different domains but my domains are as follows:

000001.mysubdomain.mydomain.com

ct000002.mysubdomain.mydomain.com

So I'm not a networking guy but I would assume that in this case both the MS SQL Server and my NodeJS Server are actually on the same domain, am I correct in assuming that or incorrect?

Some more info - in both cases the IP addresses share the same first number but the rest are different - SS.XX.XX.XX - Where SS is the same numbers and XX are different - does this suggest that they are in fact on different domains?

In addition to this if it was a domain issue then why would it work on my local machine?

So if we can eliminate that it is not a domain issue then I'm not sure where to go, here is my code, I am using the Tedious-NTLM NodeJS module - https://www.npmjs.com/package/tedious-ntlm

var tds = require("tedious-ntlm"); //Get the tedious model for NTLM connection to the SQL Server

//Set up config for logging into the DB
var config = {
    userName: 'myusername', //Username
    domainName: "mydomain", //Domain
    password: 'mypassword', //Password
    server: '000001.mysubdomain.mydomain.com' //Database address
};

function getDataFromSQLServer(callback){
    var connection = new tds.Connection(config); //Configure a connection

    //When the database is connected to we get this event
    connection.on('connect', function(err) {
            // If no error, then good to go...
            if(err){
                console.log('err = ' + err); //Log the error to the console
            }
            else{
                executeStatement(callback); //Execute the test statement
            }
        }
    );

As you can see here when my function is called I log an error, I get an error here when trying to run the code from my server but I have no issue when running it from my local machine.

To get more information on the error I have the following code:

connection.on('errorMessage',  function(err){
        console.log('full error = ' + JSON.stringify(err)); //Log the error to the console
});

Which gives me the following info:

full error = {"number":18452,"state":1,"class":14,"message":"Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.","serverName":"000001","procName":"","lineNumber":1,"name":"ERROR","event":"errorMessage"}

Again if run on my local machine everything works correctly but if I run from my server I get the errors, I am wondering if this really is a domain issue or if the error message is incorrect and there is something else wrong?

Community
  • 1
  • 1
Donal Rafferty
  • 19,707
  • 39
  • 114
  • 191
  • I don't know node.js, but it's always fishy to me when someone tells me that they're using Windows authentication and are passing in a username/password in the application. Windows auth relies on the fact that every process in the OS is running as some account and has already authenticated. So passing a username/password should be unnecessary. – Ben Thul May 06 '15 at 19:35
  • For Windows Auth, I've found using `edge` instead of `tedious` works much better. See answer here: http://stackoverflow.com/questions/33709807/how-to-connect-to-sql-server-with-windows-authentication-from-node-js-using-mssq – getglad Dec 07 '15 at 17:54

0 Answers0