I need to connect to SQL Server using nodeJs. This is the connection string normally I used for .NET
Data Source=DESKTOP-QPC8N68\SQLEXPRESS;Initial Catalog=ProjectX;Integrated Security=True
I'm using the mssql
npm package and my code as follows:
app.get('/', function (req, res) {
var sql = require("mssql");
var config = {
server: 'localhost\\SQLEXPRESS',
database: 'ProjectX',
options: {
trustedConnection: true
}
};
sql.connect(config).then(function (ar) {
console.log('connected');
console.log(ar);
}).catch(function (ex) {
console.log(ex);
});
res.send('OK');
});
I'm getting the following error
ConnectionError: Failed to connect to localhost:undefined in 15000ms
at Connection. (C:\Drive F\NodeSql\node_modules\mssql\lib\tedious.js:378:25)
name: 'ConnectionError',
message: 'Failed to connect to localhost:undefined in 15000ms',
code: 'ETIMEOUT'ConnectionError: Failed to connect to localhost:undefined in 15000ms
at Connection.
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5) at Timer.listOnTimeout (timers.js:207:5)
name: 'ConnectionError',
message: 'Failed to connect to localhost:undefined in 15000ms',
code: 'ETIMEOUT'
I'm using Windows authentication to connect to SQL Server. What is missing here and what npm package do you recommend to connect to SQL Server?