[英]why my node js is not getting connected to sql server?
I am trying to connect to sql server using node js. 我正在尝试使用节点js连接到sql服务器。 I have installed the package mssql and using sublime text editor.
我已经安装了mssql软件包,并使用了sublime文本编辑器。 this is my node js code.
这是我的节点js代码。
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 当我从命令promt运行此命令时,出现此错误
when I did Console.log(dbconfig) it was having this data 当我执行Console.log(dbconfig)时,它具有此数据
Your error it's you have to set user
and not userName
. 您的错误是您必须设置
user
而不是userName
。
Check this example from the doc : 从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. 它是用户而不是userName。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.