title: Connect to SQL Azure from Node.JS
body: <p>I have a database that I can connect to from ASP.NET. I'm now trying to connect to that database via Node.js. I'm trying to do some benchmarking. In an attempt to connect to the database via Node.js, I'm using the <a href="https://github.com/patriksimek/node-mssql" rel="nofollow">mssql package</a>. My code looks like the following:</p>
  
  <pre><code>var sql = require('mssql');
  var connectionString = {
      user: '[myUserName]',
      password: '[myPassword]',
      server: 'tcp:[serverName].database.windows.net',
      database: '[databaseName]',
  
      options: {
          encrypt: true // Use this if you're on Windows Azure
      }
  };  
  
  try {
    sql.connect(connectionString, function(err) {
      if (err) {
        console.log(err);
        return;
      }
  
      var request = new sql.Request();
      request.query('select top 5 from Logs', function(err, recordset) {
        if (err) {
          console.log(err);
          return;
        }
      });
    });
  } catch (ex1) {
  
  }
  </code></pre>
  
  <p>When I execute this code, I get an error that says:</p>
  
  <pre><code>{ name: 'ConnectionError',
    message: 'Failed to connect to tcp:[serverName].database.windows.net:1433 - getaddrinfo ENOTFOUND',
    code: 'ESOCKET' }
  </code></pre>
  
  <p>My question is, how do I connect to SQL Azure from Node.js? I'm trying to run a basic query. Unfortunately, I feel stuck. I have to be doing something improperly in my connection string. Any help is much appreciated.</p>