title: SQL Server Windows Auth error connecting from NodeJS
body: <p>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.</p>
  <p>The error I am getting is as follows:</p>
  <blockquote>
  <p>The login is from an untrusted domain and cannot be used with Windows
  authentication</p>
  </blockquote>
  <p>So I am thinking that maybe its different domains but my domains are as follows:</p>
  <blockquote>
  <p>000001.mysubdomain.mydomain.com</p>
  <p>ct000002.mysubdomain.mydomain.com</p>
  </blockquote>
  <p>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?</p>
  <p>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?</p>
  <p>In addition to this if it was a domain issue then why would it work on my local machine?</p>
  <p>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 - <a href="https://www.npmjs.com/package/tedious-ntlm" rel="nofollow noreferrer">https://www.npmjs.com/package/tedious-ntlm</a></p>
  <pre><code>var tds = require(&quot;tedious-ntlm&quot;); //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: &quot;mydomain&quot;, //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
              }
          }
      );
  </code></pre>
  <p>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.</p>
  <p>To get more information on the error I have the following code:</p>
  <pre><code>connection.on('errorMessage',  function(err){
          console.log('full error = ' + JSON.stringify(err)); //Log the error to the console
  });
  </code></pre>
  <p>Which gives me the following info:</p>
  <blockquote>
  <p>full error = {&quot;number&quot;:18452,&quot;state&quot;:1,&quot;class&quot;:14,&quot;message&quot;:&quot;Login
  failed. The login is from an untrusted domain and cannot be used with
  Windows
  authentication.&quot;,&quot;serverName&quot;:&quot;000001&quot;,&quot;procName&quot;:&quot;&quot;,&quot;lineNumber&quot;:1,&quot;name&quot;:&quot;ERROR&quot;,&quot;event&quot;:&quot;errorMessage&quot;}</p>
  </blockquote>
  <p>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?</p>