title: Nodejs mssql ConnectionError: Login failed for user ' '
body: <p>This is my code: </p>
  
  <pre><code>var sql = require("mssql");
  
  var dbConfig = {
  server: "server",
  username: "user",
  password: "password",
  database: "database"
  };
  
  function getEmp() {
  var conn = new sql.Connection(dbConfig);
  console.log(conn);
  var req = new sql.Request(conn);
  conn.connect(function (err) {
      if (err) {
          console.log(err);
          return;
      }
      req.query("SELECT * FROM Alg.User", function (err, recordset) {
          if (err) {
              console.log(err);
              return;
          }
          else {
              console.log(recordset);
          }
          conn.close();
      });
  });
  }
  
  getEmp();
  </code></pre>
  
  <p>And this is the error I'm logging:</p>
  
  <pre><code> { ConnectionError: Login failed for user ''.
  at Connection.&lt;anonymous&gt; (c:\users\milan\documents\visual studio 2015\Projects\SampleSQLConn\SampleSQLConn\node_modules\mssql\lib\tedious.js:378:25)
  at Connection.g (events.js:291:16)
  at emitOne (events.js:96:13)
  at Connection.emit (events.js:188:7)
  at Connection.processLogin7Response (c:\users\milan\documents\visual studio 2015\Projects\SampleSQLConn\SampleSQLConn\node_modules\tedious\lib\connection.js:672:16)
  at Connection.message (c:\users\milan\documents\visual studio 2015\Projects\SampleSQLConn\SampleSQLConn\node_modules\tedious\lib\connection.js:1082:21)
  at Connection.dispatchEvent (c:\users\milan\documents\visual studio 2015\Projects\SampleSQLConn\SampleSQLConn\node_modules\tedious\lib\connection.js:519:45)
  at MessageIO.&lt;anonymous&gt; (c:\users\milan\documents\visual studio 2015\Projects\SampleSQLConn\SampleSQLConn\node_modules\tedious\lib\connection.js:439:23)
  at emitNone (events.js:86:13)
  at MessageIO.emit (events.js:185:7)
  name: 'ConnectionError',
  message: 'Login failed for user \'\'.',
  code: 'ELOGIN' }
  </code></pre>
  
  <p>Anyone knows what I'm doing wrong? It looks like my variable username isn't put in the connectionstring? But I have no idea why...</p>
  
  <p>Thanks in advance!</p>
  
  <h1>Solution:</h1>
  
  <p>The problem was that in dbConfig, the username variable should be changed to user! And the sql query was wrong also, it should have been [Alg].[User], because 'User' is a keyword! </p>