I'm running a simple Node.js server on Heroku. I've set up an Azure SQL database and I'm just trying to establish a connection to it from the server. I'm using tedious.js to connect. As far as I can tell, I'm following the patterns in the docs, but the connection doesn't go through. This is the code I have (altered username and password). For now, the connect function is called upon a GET request to the "/data" page from my browser, but the page never loads and the connection never goes through. Any pointers?
var azure = require("azure-storage");
var Connection = require("tedious").Connection;
var config = {
Server : "my-db.database.windows",
username : "XXXXX",
password : "XXXXX",
options : {
port: 1433,
Database : "my-db",
connectTimeout : 3000,
},
};
var connection = new Connection(config);
function connect(request, response) {
connection.on("connect", function(error) {
//If no error, then good to go
console.log("Connected to database! Booyah.");
executeStatement();
response.send("Connected to database! Booyah.");
}, function (info) {
console.log(info);
});
}
exports.connect = connect;
Serveruri is missing.netat the end. Not sure if your real code is missing it too - that would be an issue. Also: Did you open the SQL Database firewall to allow for incoming connections from your node app?