I am using Node JS with IIS (IISNode) and Microsoft's MS SQL driver package (MSNodeSQL) to create a http server. When accessing my database via the http server I get the following error when attempting to connect to the MS SQL database:
error { [Error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified] sqlstate: 'IM002', code: 0 }
But if I try to access the database locally on my server without the http server, then it connects perfectly fine. The ODBC driver is obviously installed.
Here is my code:
var http = require('http');
var sql = require('msnodesql');
var conn_str = "Driver={SQL Server Native Client 11.0}; Server=***; Database=***; UID=***; PWD=***;";
var blah = "";
http.createServer(function (req, res) {
sql.open(conn_str, function (err, conn) {
if (err) {
console.log("error", err);
res.end("error");
return;
}
conn.queryRaw("SELECT * FROM ProductLinks", function (err, results) {
if (err) {
res.end('failed2');
return;
}
for (var i = 0; i < results.rows.length; i++) {
blah += "Id: " + results.rows[i][0] + " Name: " + results.rows[i][1] + " Text: " + results.rows[i][2] + " Link: " + results.rows[i][3];
}
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(blah);
});
});
}).listen(process.env.PORT);
I have a feeling it may be down to permissions somewhere since it works locally and not remotely, but I'm not entirely sure. Plus when locally, Node JS is being executed under a different user as opposed to IIS_IUSR which IISNode uses.
Any help would be great, thanks!