2016-11-07 166 views
0

我正在使用Sequelize連接到SQLServer數據庫。 我用這個配置對於​​Sequelize:使用sequelize連接失敗的sql服務器

module.exports = { 
    database: 'dbname', 
    username: 'sa', 
    password: 'password', 
    options: { 
     dialect: 'mssql', 
     host: 'host address', 
     port: 1433, 
     dialectOptions: { 
      instanceName: 'instancename' 
     } 
    }  
} 

,但我得到這個錯誤:

ConnectionError: Login failed for user 'sa'.

我的SQL Server配置管理器已經啓用 'SQL Server瀏覽' 和 'TCP/IP協議' 。 我的實例名稱是默認的'MSSQLSERVER'。

我已經安裝了繁瑣。從Node.js的

堆棧跟蹤:

{ SequelizeConnectionError: Login failed for user 'sa'. 
    at Connection.<anonymous> (P:\ChatRoom\node_modules\sequelize\lib\dialects\mssql\connection-manager.js:109:16) 
    at emitOne (events.js:96:13) 
    at Connection.emit (events.js:188:7) 
    at Connection.processLogin7Response (P:\ChatRoom\node_modules\tedious\lib\connection.js:672:16) 
    at Connection.message (P:\ChatRoom\node_modules\tedious\lib\connection.js:1082:21) 
    at Connection.dispatchEvent (P:\ChatRoom\node_modules\tedious\lib\connection.js:519:45) 
    at MessageIO.<anonymous> (P:\ChatRoom\node_modules\tedious\lib\connection.js:439:23) 
    at emitNone (events.js:86:13) 
    at MessageIO.emit (events.js:185:7) 
    at ReadablePacketStream.<anonymous> (P:\ChatRoom\node_modules\tedious\lib\message-io.js:92:15) 
    at emitOne (events.js:96:13) 
    at ReadablePacketStream.emit (events.js:188:7) 
    at readableAddChunk (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_readable.js:213:18) 
    at ReadablePacketStream.Readable.push (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_readable.js:172:10) 
    at ReadablePacketStream.Transform.push (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_transform.js:123:32) 
    at ReadablePacketStream._transform (P:\ChatRoom\node_modules\tedious\lib\message-io.js:57:16) 
    name: 'SequelizeConnectionError', 
    message: 'Login failed for user \'sa\'.', 
    parent: 
    { ConnectionError: Login failed for user 'sa'. 
     at ConnectionError (P:\ChatRoom\node_modules\tedious\lib\errors.js:12:12) 
     at Parser.<anonymous> (P:\ChatRoom\node_modules\tedious\lib\connection.js:216:38) 
     at emitOne (events.js:96:13) 
     at Parser.emit (events.js:188:7) 
     at Parser.<anonymous> (P:\ChatRoom\node_modules\tedious\lib\token\token-stream-parser.js:42:15) 
     at emitOne (events.js:96:13) 
     at Parser.emit (events.js:188:7) 
     at readableAddChunk (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_readable.js:213:18) 
     at Parser.Readable.push (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_readable.js:172:10) 
     at Parser.Transform.push (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_transform.js:123:32) 
     at doneParsing (P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:87:17) 
     at P:\ChatRoom\node_modules\tedious\lib\token\infoerror-token-parser.js:46:5 
     at P:\ChatRoom\node_modules\tedious\lib\token\infoerror-token-parser.js:13:19 
     at P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:224:9 
     at Parser.awaitData (P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:121:9) 
     at Parser.readUInt32LE (P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:221:12) message: 'Login failed for user \'sa\'.', code: 'ELOGIN' }, 
    original: 
    { ConnectionError: Login failed for user 'sa'. 
     at ConnectionError (P:\ChatRoom\node_modules\tedious\lib\errors.js:12:12) 
     at Parser.<anonymous> (P:\ChatRoom\node_modules\tedious\lib\connection.js:216:38) 
     at emitOne (events.js:96:13) 
     at Parser.emit (events.js:188:7) 
     at Parser.<anonymous> (P:\ChatRoom\node_modules\tedious\lib\token\token-stream-parser.js:42:15) 
     at emitOne (events.js:96:13) 
     at Parser.emit (events.js:188:7) 
     at readableAddChunk (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_readable.js:213:18) 
     at Parser.Readable.push (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_readable.js:172:10) 
     at Parser.Transform.push (P:\ChatRoom\node_modules\tedious\node_modules\readable-stream\lib\_stream_transform.js:123:32) 
     at doneParsing (P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:87:17) 
     at P:\ChatRoom\node_modules\tedious\lib\token\infoerror-token-parser.js:46:5 
     at P:\ChatRoom\node_modules\tedious\lib\token\infoerror-token-parser.js:13:19 
     at P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:224:9 
     at Parser.awaitData (P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:121:9) 
     at Parser.readUInt32LE (P:\ChatRoom\node_modules\tedious\lib\token\stream-parser.js:221:12) message: 'Login failed for user \'sa\'.', code: 'ELOGIN' } } 

的用戶名和我的數據庫的密碼是完全測試,並與連接,而「Server身份驗證」設置爲「SQL Server和Windows身份驗證模式」。

我真的很感激任何建議或幫助解決這個問題。

+1

你還可以從SQLServer檢查日誌嗎?它應該包含解釋登錄失敗原因的一些信息。 (無法接受傳入的連接?錯誤的憑據?錯誤的身份驗證協議?...) –

+0

謝謝@ Pierre-YvesO。我檢查了日誌並發現問題。 –

回答

0

您的服務器上是否啓用了SA用戶?你可以執行下面的sql來啓用它,如果沒有的話。

USE [master] 
GO 
ALTER LOGIN [sa] WITH PASSWORD='password' 
GO 
ALTER LOGIN [sa] ENABLE 
GO 
+0

我已經提到過: 我的數據庫的用戶名和密碼已經過完全測試並與 –