[英]why my node js is not getting connected to sql server?
我正在尝试使用节点js连接到sql服务器。 我已经安装了mssql软件包,并使用了sublime文本编辑器。 这是我的节点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();
当我执行Console.log(dbconfig)时,它具有此数据
您的错误是您必须设置user
而不是userName
。
从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
}
}
它是用户而不是userName。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.