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 mssql package. My code looks like the following:
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) {
}
When I execute this code, I get an error that says:
{ name: 'ConnectionError',
message: 'Failed to connect to tcp:[serverName].database.windows.net:1433 - getaddrinfo ENOTFOUND',
code: 'ESOCKET' }
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.