【问题标题】:SQL Server database configuration error in sails.js using mssql使用mssql的sails.js中的SQL Server数据库配置错误
【发布时间】:2017-01-19 20:01:07
【问题描述】:

我正在尝试使用我的sails.js 项目连接到SQL Server 数据,并且我使用mssql 连接到数据库。

我没有任何命名实例,并且我正在使用 Windows 身份验证登录,到目前为止我在 testController.js 中编写的代码是

/**
 * testController
 *
 * @module      :: Controller
 * @description :: A set of functions called `actions`.
 *
 *                 Actions contain code telling Sails how to respond to a certain type of request.
 *                 (i.e. do stuff, then send some JSON, show an HTML page, or redirect to another URL)
 *
 *                 You can configure the blueprint URLs which trigger these actions (`config/controllers.js`)
 *                 and/or override them with custom routes (`config/routes.js`)
 *
 *                 NOTE: The code you write here supports both HTTP and Socket.io automatically.
 *
 * @docs        :: http://sailsjs.org/#!documentation/controllers
 */

module.exports = {


    /**
     * Action blueprints:
     *    `/new/index`
     *    `/new`
     */
    index: function(req, res) {


        var config = {
            // user: '(local)',
            // password: '',
            //server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
            server: '192.168.0.109', // You can use 'localhost\\instance' to connect to named instance
            database: 'test',

            options: {
                //encrypt: true // Use this if you're on Windows Azure
                trustedConnection: true,
                // port: 1444

            }
        }

        var sql = require('mssql');
        var connection = new sql.Connection(config, function(err) {
            if (err) {
                console.log("Error opening the connection!", err);
                return;
            }
            conn.queryRaw("SELECT TOP 10 FirstName, LastName FROM Person.Person", function(err, results) {
                if (err) {
                    console.log("Error running query!");
                    return;
                }
                for (var i = 0; i < results.rows.length; i++) {
                    console.log("FirstName: " + results.rows[i][0] + " LastName: " + results.rows[i][1]);
                }
            });
        });

    },

    _config: {}

};

但它会触发错误

打开连接时出错! { [ConnectionError: 用户 '' 登录失败。]
名称:“连接错误”,
message: '用户\'\'登录失败。',
代码:'ELOGIN' }

我真的很困惑,不知道在哪里可以找到带有windows authentication 的文档,我只能找到trustedConnection: true,

请就这个问题指导我。

谢谢

【问题讨论】:

    标签: sql-server node.js sql-server-2008 sails.js


    【解决方案1】:

    我可能回答得这么晚了,但是 mssql 通常在使用 Windows Auth 时遇到问题。改为使用 Edge.js 进行连接。

    【讨论】:

      猜你喜欢
      • 2013-08-07
      • 1970-01-01
      • 1970-01-01
      • 2020-08-13
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多