2015-10-14 53 views
2

我想用我的sails.js項目連接到SQL Server數據,並且我已經使用mssql連接到數據庫。使用mssql在sails.js中的SQL Server數據庫配置錯誤

我沒有任何的命名實例,我在使用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: {} 

}; 

但它引發的錯誤

Error opening the connection! { [ConnectionError: Login failed for user ''.]
name: 'ConnectionError',
message: 'Login failed for user \'\'.',
code: 'ELOGIN' }

我真的很困惑,不知道從哪裏找到它的文檔與windows authentication,所有我能找到的是trustedConnection: true,

認罪我指導我解決這個問題。

感謝

回答

0

我可能回答這個較晚,但MSSQL通常使用的是Windows身份驗證的麻煩。改用Edge.js來建立連接。