从 Node.js 连接到远程 Microsoft SQL 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4728385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 13:49:54  来源:igfitidea点击:

Connecting to a remote Microsoft SQL server from Node.js

node.jsnode-mssql

提问by A Wizard Did It

I was wondering if anyone was aware of a way to connect to a Microsoft SQL database from Node.js. I'm aware of the MySQL drivers, but I have data that I need to pull from a MS SQL database and would rather pull directly from Node.js rather than hack a PHP script of some sort in place.

我想知道是否有人知道从 Node.js 连接到 Microsoft SQL 数据库的方法。我知道 MySQL 驱动程序,但我有我需要从 MS SQL 数据库中提取的数据,并且宁愿直接从 Node.js 中提取而不是在适当的位置破解某种 PHP 脚本。

采纳答案by Cade Roux

I suspect you'll have to wrap your SQL Server with a JSON outputting web-service. On the positive side, it should be relatively easy to do.

我怀疑您必须使用 JSON 输出 Web 服务来包装您的 SQL Server。从积极的方面来说,它应该相对容易做到。

Be nice if the JavaScript engine in node.js could do this: (from How to connect to SQL Server database from JavaScript in the browser?):

如果 node.js 中的 JavaScript 引擎可以做到这一点,那就太好了:(来自如何从浏览器中的 JavaScript 连接到 SQL Server 数据库?):

var connection = new ActiveXObject("ADODB.Connection") ;

var connectionstring="Data Source=<server>;Initial Catalog=<catalog>;User ID=<user>;Password=<password>;Provider=SQLOLEDB";

connection.Open(connectionstring);
var rs = new ActiveXObject("ADODB.Recordset");

rs.Open("SELECT * FROM table", connection);
rs.MoveFirst
while(!rs.eof)
{
   document.write(rs.fields(1));
   rs.movenext;
}

rs.close;
connection.close;

回答by Tracker1

I would recommend node-mssql, which is a nice wrapper for other connectors, the default being my previous choice (Tedious) bringing a bit nicer of an interface. This is a JavaScript implimentation, with no compilation requirements, meaning you can work in windows and non-windows environments alike.

我会推荐node-mssql,它是其他连接器的一个很好的包装器,默认值是我之前的选择 ( Tedious) 带来了更好的界面。这是一个 JavaScript 实现,没有编译要求,这意味着您可以在 Windows 和非 Windows 环境中工作。

Another option, if you don't mind bringing in .Net or Mono with a binary bridge would be to use edge.js. Which can be very nice if you want to leverage .Net libraries in node.js

另一种选择,如果您不介意使用二进制网桥引入 .Net 或 Mono 将使用edge.js。如果您想利用 node.js 中的 .Net 库,这会非常好

node-tdsis abandoned, node-odbcdoesn't work with windows, and the MS node-sqlserverdriver doesn't seem to work on non-windows (and has some goofy requirements).

node-tds被放弃,node-odbc不适用于 Windows,并且 MS node-sqlserver驱动程序似乎不适用于非 Windows(并且有一些愚蠢的要求)。

回答by wankdanker

If you are connecting to Mssql from linux you can use node-odbc ( https://github.com/w1nk/node-odbc) with the freetds odbc driver. I am using this in production and its faster than wrapping a web service.

如果您从 linux 连接到 Mssql,您可以将 node-odbc ( https://github.com/w1nk/node-odbc) 与 freetds odbc 驱动程序一起使用。我在生产中使用它,它比包装 Web 服务更快。

回答by treythomas123

New answer for 2015: The ORM package Sequelizenow supports MS SQL, using the Tediousdriver under the covers.

2015 年的新答案:ORM 包Sequelize现在支持 MS SQL,在幕后使用Tedious驱动程序。

This is the best way I've found to interact with Microsoft SQL Server.

这是我发现的与 Microsoft SQL Server 交互的最佳方式。

回答by Sneaky Wombat

Another option, from Microsoft even,

另一个选择,甚至来自微软,

http://www.microsoft.com/en-us/download/details.aspx?id=29995

http://www.microsoft.com/en-us/download/details.aspx?id=29995

Or a linux sql client driver via odbc:

或者通过 odbc 的 linux sql 客户端驱动程序:

http://www.microsoft.com/en-us/download/details.aspx?id=28160

http://www.microsoft.com/en-us/download/details.aspx?id=28160

回答by Fosco

Just today I released a new module, for windows only, allowing native and asynchronous use of MSSQL. It's called TSQLFTW, and currently supports connecting and querying the database. It returns results in JSON.

就在今天,我发布了一个仅适用于 Windows 的新模块,允许本地和异步使用 MSSQL。它叫做TSQLFTW,目前支持连接和查询数据库。它以 JSON 格式返回结果。

Check out the Github here: https://github.com/gfosco/tsqlftw

在此处查看 Github:https: //github.com/gfosco/tsqlftw

Hacker News submission/comments: http://news.ycombinator.com/item?id=3353389

黑客新闻提交/评论:http: //news.ycombinator.com/item?id=3353389