Node.js 和 Microsoft SQL Server

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5156806/
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:54:16  来源:igfitidea点击:

Node.js and Microsoft SQL Server

sql-servernode.jsnode-mssqltedious

提问by Khuram Malik

Is there any way I can get my Node.js app to communicate with Microsoft SQL? I haven't seen any MS SQL drivers out there in the wild?

有什么方法可以让我的 Node.js 应用程序与 Microsoft SQL 通信?我还没有在野外看到任何 MS SQL 驱动程序?

I'm putting a very simple app together and need to be able to communicate with an existing MS SQL database (otherwise I would have gone with mongoDB or Redis)

我正在将一个非常简单的应用程序放在一起,并且需要能够与现有的 MS SQL 数据库进行通信(否则我会使用 mongoDB 或 Redis)

采纳答案by kop48

We just released preview drivers for Node.JS for SQL Server connectivity. You can find them here: http://blogs.msdn.com/b/sqlphp/archive/2012/06/08/introducing-the-microsoft-driver-for-node-js-for-sql-server.aspx

我们刚刚发布了用于 SQL Server 连接的 Node.JS 预览版驱动程序。你可以在这里找到它们:http: //blogs.msdn.com/b/sqlphp/archive/2012/06/08/introducing-the-microsoft-driver-for-node-js-for-sql-server.aspx

回答by Christiaan Westerbeek

The original question is old and now using node-mssqlas answered by @Patrik ?imek that wraps Tediousas answered by @Tracker1 is the best way to go.

原来的问题是旧的,现在使用节点MSSQL作为回答@Patrik?imek一个封装繁琐由@ Tracker1是最好的方式去作为回答。

The Windows/Azure node-sqlserver driveras mentioned in the accepted answer requires you to install a crazy list of prerequisites: Visual C++ 2010, SQL Server Native Client 11.0, python 2.7.x and probably also Windows 7 SDK for 64-bit on your server. You don't want to install all these GB's of software on your Windows Server if you ask me.

已接受的答案中提到的Windows/Azure node-sqlserver 驱动程序要求您安装一个疯狂的先决条件列表:Visual C++ 2010、SQL Server Native Client 11.0、python 2.7.x 以及 Windows 7 SDK for 64-bit on your服务器。如果你问我,你不想在你的 Windows Server 上安装所有这些 GB 的软件。

You really want to use Tedious. But alsouse node-mssqlto wrap it and make coding a lot easier.

您真的很想使用Tedious。但使用node-mssql来包装它并使编码更容易。

Update August 2014

2014 年 8 月更新

  • Both modules are still actively maintained. Issues are responded on quite quickly and efficiently.
  • Both modules support SQL Server 2000 - 2014
  • Streaming supported since node-mssql 1.0.1
  • 这两个模块仍在积极维护中。问题得到了相当快速和有效的回应。
  • 两个模块都支持 SQL Server 2000 - 2014
  • 自 node-mssql 1.0.1 起支持流式传输

Update February 2015 - 2.x (stable, npm)

2015 年 2 月更新 - 2.x(稳定版,npm)

  • Updated to latest Tedious 1.10
  • Promises
  • Pipe request to object stream
  • Detailed SQL errors
  • Transaction abort handling
  • Integrated type checks
  • CLI
  • Minor fixes
  • 更新到最新的乏味 1.10
  • 承诺
  • 管道请求到对象流
  • 详细的 SQL 错误
  • 事务中止处理
  • 集成类型检查
  • 命令行界面
  • 小修正

This is plain Tedious:

这很乏味

var Connection = require('tedious').Connection;
var Request = require('tedious').Request;

var config = {
  server: '192.168.1.212',
  userName: 'test',
  password: 'test'
};

var connection = new Connection(config);

connection.on('connect', function(err) {
    executeStatement();
  }
);

function executeStatement() {
  request = new Request("select 42, 'hello world'", function(err, rowCount) {
    if (err) {
      console.log(err);
    } else {
      console.log(rowCount + ' rows');
    }

    connection.close();
  });

  request.on('row', function(columns) {
    columns.forEach(function(column) {
      if (column.value === null) {
        console.log('NULL');
      } else {
        console.log(column.value);
      }
    });
  });

  request.on('done', function(rowCount, more) {
    console.log(rowCount + ' rows returned');
  });

  // In SQL Server 2000 you may need: connection.execSqlBatch(request);
  connection.execSql(request);
}

Here comes node-mssqlwhich has Tedious as a dependency. Use this!

这里是node-mssql,它具有乏味作为依赖项。用这个!

var sql     = require('mssql');

var config = {
  server: '192.168.1.212',
  user:     'test',
  password: 'test'
};

sql.connect(config, function(err) {
    var request = new sql.Request();
    request.query("select 42, 'hello world'", function(err, recordset) {
        console.log(recordset);
    });
});

回答by Chad Retz

A couple of new node.js SQL server clients have just released recently. I wrote one called node-tdsand there is another called tedious

最近刚刚发布了几个新的 node.js SQL 服务器客户端。我写了一个叫node-tds,还有一个叫tedious

回答by John Boker

You could maybe use node-tds.js:

你也许可以使用node-tds.js

An exciting implementation of the TDS protocol for node.js to allow communication with sql server...

USAGE:

var mssql = require('./mssql');
var sqlserver = new mssql.mssql();
sqlserver.connect({'Server':__IP__,'Port':'1433','Database':'','User Id':'','Password':''});
var result = sqlserver.execute("SELECT * FROM wherever;");

node.js 的 TDS 协议的一个令人兴奋的实现,允许与 sql server 通信......

用法:

var mssql = require('./mssql');
var sqlserver = new mssql.mssql();
sqlserver.connect({'Server':__IP__,'Port':'1433','Database':'','User Id':'','Password':''});
var result = sqlserver.execute("SELECT * FROM wherever;");

回答by Patrik ?imek

There is another module you can use - node-mssql. It uses other TDS modules as drivers and offer easy to use unified interface. It also add extra features and bug fixes.

您可以使用另一个模块 - node-mssql。它使用其他 TDS 模块作为驱动程序,并提供易于使用的统一接口。它还添加了额外的功能和错误修复。

Extra features:

额外功能:

  • Unified interface for multiple MSSQL drivers
  • Connection pooling with Transactions and Prepared statements
  • Parametrized Stored Procedures for all drivers
  • Serialization of Geography and Geometry CLR types
  • Smart JS data type to SQL data type mapper
  • Support both Promises and standard callbacks
  • 多个 MSSQL 驱动程序的统一接口
  • 具有事务和准备语句的连接池
  • 所有驱动程序的参数化存储过程
  • Geography 和 Geometry CLR 类型的序列化
  • 智能 JS 数据类型到 SQL 数据类型映射器
  • 支持 Promise 和标准回调

回答by Tracker1

(duplicating my answer from another question).

(从另一个问题复制我的答案)。

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 Jeno Laszlo

TSQLFTW - T-SQL For The WIN(dows) - by Fosco Marotto https://github.com/gfosco/tsqlftw

TSQLFTW - T-SQL For The WIN(dows) - Fosco Marotto https://github.com/gfosco/tsqlftw

It is a C# and ADO .NET managed code solution, with a C++ wrapper that Node.js can import and work with.

它是一个 C# 和 ADO .NET 托管代码解决方案,带有一个 C++ 包装器,Node.js 可以导入和使用它。



If you know .NET you could try WCF Data Services (ADO.NET Data Services); write an WCF app for data access and use odata (REST on steroids) to interact with the database

如果您了解 .NET,您可以尝试 WCF 数据服务(ADO.NET 数据服务);编写用于数据访问的 WCF 应用程序并使用 odata(类固醇上的 REST)与数据库进行交互



If you are into SOA and use SQL Server 2005 you could check out the Native XML Web Services for Microsoft SQL Server 2005

如果您使用 SOA 并使用 SQL Server 2005,您可以查看 Microsoft SQL Server 2005 的 Native XML Web Services

http://msdn.microsoft.com/en-us/library/ms345123(v=sql.90).aspx

http://msdn.microsoft.com/en-us/library/ms345123(v=sql.90).aspx

You could access SQL Server as a web service (HTTP, SOAP)

您可以将 SQL Server 作为 Web 服务(HTTP、SOAP)访问

回答by silverfighter

Microsoft (The Windows Azure Team) just released a node driver for SQL SERVER.

Microsoft(Windows Azure 团队)刚刚发布了 SQL SERVER 的节点驱动程序。

It has no package for npm yert, as far as I know, but it is open sourced. And the accepting community contribution too.

据我所知,它没有用于 npm yert 的包,但它是开源的。以及接受社区贡献。

https://github.com/WindowsAzure/node-sqlserver

https://github.com/WindowsAzure/node-sqlserver

Introduction blog post here:

介绍博客文章在这里:

http://blogs.msdn.com/b/sqlphp/archive/2012/06/08/introducing-the-microsoft-driver-for-node-js-for-sql-server.aspx

http://blogs.msdn.com/b/sqlphp/archive/2012/06/08/introducing-the-microsoft-driver-for-node-js-for-sql-server.aspx

回答by user1467882

There is an update from Microsoft. Here is a series of blog posts (part 1and part 2).

有来自 Microsoft 的更新。这是一系列博客文章(第 1部分第 2 部分)。

回答by Mike Griffin

If you are running on .NET look at entityspaces.js at, we are creating an entire universal ORM for Node.js that will not require a WCF JSON service ... https://github.com/EntitySpaces/entityspaces.js

如果您在 .NET 上运行,请查看 entityspaces.js,我们正在为 Node.js 创建一个完整的通用 ORM,它不需要 WCF JSON 服务...... https://github.com/EntitySpaces/entityspaces.js

If you are using MSFT backend technology you could use it now, however, we are creating a universal Node.js ORM and will have more information on that soon

如果你正在使用 MSFT 后端技术,你现在可以使用它,但是,我们正在创建一个通用的 Node.js ORM,很快就会有更多信息