我正在尝试从我的sails.js应用程序中连接到SQL Server数据库。我使用sergeibelov/sails-mssql连接到远程Azure实例。
我在config / adapters.js中设置了数据库信息。
当我尝试使用有效凭据进行连接时,出现以下错误:
error: Hook failed to load: orm (Error: Incorrect syntax near the keyword 'user'.)
error: Error encountered while loading Sails core!
error: Error: Incorrect syntax near the keyword 'user'.
at Request.userCallback (TestApp/node_modules/sails-mssql/node_modules/mssql/lib/tedious.js:352:23)
at Request.callback (TestApp/node_modules/sails-mssql/node_modules/mssql/node_modules/tedious/lib/request.js:24:27)
at Connection.STATE.SENT_CLIENT_REQUEST.events.message (TestApp/node_modules/sails-mssql/node_modules/mssql/node_modules/tedious/lib/connection.js:198:29)
at Connection.dispatchEvent (TestApp/node_modules/sails-mssql/node_modules/mssql/node_modules/tedious/lib/connection.js:465:59)
at Connection.c.dispatchEvent (TestApp/node_modules/sails-mssql/node_modules/mssql/lib/tedious.js:206:26)
at MessageIO. (TestApp/node_modules/sails-mssql/node_modules/mssql/node_modules/tedious/lib/connection.js:419:20)
at MessageIO.EventEmitter.emit (events.js:92:17)
at MessageIO.eventData (TestApp/node_modules/sails-mssql/node_modules/mssql/node_modules/tedious/lib/message-io.js:59:21)
at Socket. (TestApp/node_modules/sails-mssql/node_modules/mssql/node_modules/tedious/lib/message-io.js:3:59)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket. (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
at TCP.onread (net.js:526:21)
当我更改为无效用户时,我收到了另一个错误:
error: Hook failed to load: orm (Error: Login failed; one or more errorMessage events should have been emitted)
error: Error encountered while loading Sails core!
error: Error: Login failed; one or more errorMessage events should have been emitted
at TestApp/node_modules/sails-mssql/node_modules/mssql/lib/tedious.js:238:19
at TestApp/node_modules/sails-mssql/node_modules/mssql/node_modules/generic-pool/lib/generic-pool.js:271:11
at Connection.connect (TestApp/node_modules/sails-mssql/node_modules/mssql/lib/tedious.js:215:24)
at Connection.g (events.js:180:16)
at Connection.EventEmitter.emit (events.js:95:17)
at Connection.processLogin7Response (TestApp/node_modules/sails-mssql/node_modules/mssql/node_modules/tedious/lib/connection.js:592:12)
at Connection.STATE.SENT_LOGIN7_WITH_STANDARD_LOGIN.events.message (TestApp/node_modules/sails-mssql/node_modules/mssql/node_modules/tedious/lib/connection.js:153:23)
at Connection.dispatchEvent (TestApp/node_modules/sails-mssql/node_modules/mssql/node_modules/tedious/lib/connection.js:465:59)
at Connection.c.dispatchEvent (TestApp/node_modules/sails-mssql/node_modules/mssql/lib/tedious.js:206:26)
at MessageIO. (TestApp/node_modules/sails-mssql/node_modules/mssql/node_modules/tedious/lib/connection.js:419:20)
at MessageIO.EventEmitter.emit (events.js:92:17)
at MessageIO.eventData (TestApp/node_modules/sails-mssql/node_modules/mssql/node_modules/tedious/lib/message-io.js:59:21)
at Socket. (TestApp/node_modules/sails-mssql/node_modules/mssql/node_modules/tedious/lib/message-io.js:3:59)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket. (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
at emitReadable (_stream_readable.js:404:5)
at readableAddChunk (_stream_readable.js:165:9)
at Socket.Readable.push (_stream_readable.js:127:10)
at TCP.onread (net.js:526:21)
鉴于系统没有在关键字' user'""""""""附近发出错误#34;错误语法当我使用无效用户时,我认为第一条错误信息是红色鲱鱼。
有关如何解决这个问题的想法吗?
答案 0 :(得分:1)
解决了它。
结果用户与登录数据库的用户没有任何关系(config / adapters.js中的'user'设置)。
我创建了一个名为user的模型和控制器(sails generate user)。连接到数据库后,sails尝试将“createdAt”和“updatedAt”字段添加到用户表。但是我连接的数据库用户没有写权限,所以它抛出了一个错误。
在数据库中创建了正确的列后,一切正常。