【问题标题】:Access SQL Server from node.js on Linux在 Linux 上从 node.js 访问 SQL Server
【发布时间】:2014-05-12 15:40:50
【问题描述】:

在 Linux 上运行时,如何从 node.js 连接到 SQL Server 或 SQL Azure。

我在 npm 上找到的驱动都需要 Windows + VS2005。有没有办法从 Linux 访问 SQL Server?

【问题讨论】:

    标签: sql-server node.js azure azure-sql-database


    【解决方案1】:

    nodejs中的mssql包可以适配下一个驱动:

    • Tedious by Mike D Pilsbury(纯 javascript - windows/osx/linux)
    • Microsoft Corporation 的适用于 SQL Server 的 Node.js 的 Microsoft 驱动程序(本机 - 仅限 Windows)
    • Chad Retz 的 node-tds(纯 javascript - windows/osx/linux)

    据说node-tdsTedious都可以在linux上运行。

    【讨论】:

    • 试过了,但我无法建立连接,你有一个可行的例子吗?
    【解决方案2】:

    我找到了一个可行的解决方案,直接使用'tedious'。

    var Connection = require('tedious').Connection;
    
    var config = {
        userName: 'myuser@servername',
        password: 'mypassword',
        server: 'servername.database.windows.net',
    
       // If you're on Windows Azure, you will need this:
       options: {
           encrypt: true
       }
    };
    var connection = new Connection(config);
    
    connection.on('connect', function(err) {
        if(err)
            console.log(err)
        else
            console.log('works!!!!!')
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-14
      • 1970-01-01
      • 1970-01-01
      • 2016-04-08
      • 2010-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多