简体   繁体   English

Node.js 与 SQL 服务器

[英]Node.js with SQL Server

Has anyone had any success getting Node to communicate with a SQL Server database?有没有人成功让 Node 与 SQL 服务器数据库进行通信?

I've tried all the solutions posted on Stackoverflow (although all relevant questions seem to be about a year old) and none of them have worked.我已经尝试了 Stackoverflow 上发布的所有解决方案(尽管所有相关问题似乎已有一年之久),但都没有奏效。

Some of the packages I've tried:我尝试过的一些软件包:

  • msnodesql (Unable to get it to install successfully), msnodesql(无法成功安装),
  • mssql, tedious (Always errors out on socket connection) mssql,乏味(套接字连接总是出错)

and some others that I can't remember their names还有一些我不记得他们的名字

I think all the packages are out of date or not being maintained anymore, as far as I can see there is no defacto standard.我认为所有的软件包都已过时或不再维护,据我所知没有事实上的标准。 I'm starting to think I should abandon trying to use a SQL Server database and switch to MySQL instead?我开始认为我应该放弃尝试使用 SQL 服务器数据库并改用 MySQL?

I'm developing in Visual Studio 2012 and I also have SQL Server 2012.我在 Visual Studio 2012 中开发,我也有 SQL Server 2012。

I'am author of node-mssql module and i would like to help you solve your problem. 我是node-mssql模块的作者,我想帮助您解决问题。 Could you please provide more information about the errors you get and config you're using? 您能否提供有关所得到的错误和配置信息的更多信息? I have made some changes in connection errors recently, so maybe you could try latest version 0.5.0. 我最近在连接错误方面做了一些更改,因此也许您可以尝试使用最新版本0.5.0。

Also you could try precompiled msnodesql drivers here . 您也可以在这里尝试预编译的msnodesql驱动程序。 I was also unable to install it on my machine via npm. 我也无法通过npm将其安装在我的计算机上。 If this will work for you, try using node-mssql with msnodesql as an optional driver, it can save you a lot of lines of code and make you work with SQL Server more enjoyable. 如果这对您有用,请尝试将node-mssql与msnodesql作为可选驱动程序一起使用,它可以节省很多代码行,并使您使用SQL Server更加有趣。

this setting work in express.js 2022, sql server 2014此设置适用于 express.js 2022、sql 服务器 2014

var sql = require('mssql');
var config = {
user: 'your user',
password: 'your password',
server: 'your server', 
database: 'your database',
"options": {
          "encrypt": false,
          "enableArithAbort": true,
          "trustServerCertificate":false
          }
};


sql.connect(config, function (err) {

if (err) console.log(err);

// create Request object
var request = new sql.Request();

// query to the database and get the records
request.query('select * from a_pinfinger', function (err, recordset) {

    if (err) console.log(err)

    // send records as a response
    //res.send(recordset);
    console.log(recordset);
});
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM