Node JS and SQL Server 2008 R2 Express

2.6k views Asked by At

I want to use NodeJS to connect to a SQL Server 2008 R2 Express database. I've looked around at what NPM has to offer. Have tried mssql, mssql-simple and node-SQLServer.

Some of them can be installed some do not. And those who do, will not access SQL Server.

Error when using mssql:

[Error: connection to .\SQLEXPRESS:1433 - failed Error: getaddrinfo ENOENT]
var sql = require('mssql');
var config = {
user: 'root',
password: 'xxx',
server: '.\SQLEXPRESS',
database: 'test'
} var connection = new sql.Connection(config, function(err) {
console.log(err);
});

If there is anyone who has got something to work between NodeJS and SQL Server Express? Which module and version do you use?

3

There are 3 answers

1
Krister Johansson On BEST ANSWER

Problem was that i did not have TCP/IP Enabled. How to check and Enable MSSQL TCP/IP MSDN Next you do not have to use "server: '.\SQLEXPRESS'" after enabled TCP/IP 127.0.0.1 works fine!

1
Hasan Aydeğer On

// const sql = require("msnodesqlv8");

USE THIS

npm i msnodesqlv8

it is easy to use

0
SRahmani On

you could also just put 'localhost' as your server.