Reputation: 173
I am trying to connect to sql server using node js. I have installed the package mssql and using sublime text editor. this is my node js code.
var sql = require('mssql');
var dbConfig={
server:'CCI-LPT-21',
userName: 'sa',
password: 'sa123#',
port:1433,
options: {
instanceName: 'MSSQLSERVER2K12',
database: 'HRApp',
debug: {
packet: false,
payload: false,
token: false,
data: false
},
}
};
function getEmp()
{
//console.log(dbConfig);
var conn = new sql.Connection(dbConfig);
var req = new sql.Request(conn);
//console.log(conn)
conn.connect(function(err){
if(err){console.log(err);
return;
}
req.query("select * from Team",function(err,recordset){
if(err){
console.log(err);
return;
}
else
{
console.log(recordset);
}
conn.close();
})
})
}
getEmp();
when I run this from command promt,I get this error
when I did Console.log(dbconfig) it was having this data
Upvotes: 0
Views: 217
Reputation: 5529
Your error it's you have to set user
and not userName
.
Check this example from the doc:
var config = {
user: '...',
password: '...',
server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
database: '...',
options: {
encrypt: true // Use this if you're on Windows Azure
}
}
It's user and not userName.
Upvotes: 4