简体   繁体   English

为什么我的节点js无法连接到sql server?

[英]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.

相关问题 为什么我无法将 SQL Server 连接到我的节点 js - Why Can't I connect SQL Server to my node js 为什么我的本地node.js / express服务器的响应中没有得到JSON对象? - Why am I not getting a JSON object in the response from my local node.js/express server? 如何确定为什么我的node.js服务器上出现503错误? - How do I determine why I'm getting 503 errors on my node.js server? 为什么不是我的hello world node.js tcp服务器获取任何连接? - Why isn't my hello world node.js tcp server getting any connections? Azure 上的 SQL Server 连接到 REST API Express.js/Node.js [TypeError: req.sql is not a function] - SQL Server on Azure connected to REST API Express.js/Node.js [TypeError: req.sql is not a function] 继续在我的 node.js 服务器上收到以下警告 - Keep on getting the following warning on my node.js server 无法让我的node.js服务器监听 - Trouble getting my node.js server to listen with 为什么我的Node.js被“程序终止”而没有错误 - Why is my Node.js getting “program terminated” without an error 为什么我的Node.js服务器挂起了这个小脚本? - Why does my Node.js server hang with this small script? 错误:使用 Node.js 连接到 mysql 服务器时读取 ECONNRESET - Error: read ECONNRESET when connected to a mysql server with Node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM