sails MSSQL DB update error - sails.js

I could not able to do MSSQL update from sails. I am facing below errors.
User.update({ id: 1 },
{ id: 1, name: 'test' }).exec(function afterwards (err, user) {
if (err) {
console.log(err);
} else {
console.log("Users updated:", users);
}
});
2018-03-21T08:21:52.868Z - error: error: Error (E_UNKNOWN) ::
Encountered an unexpected error RequestError: Incorrect syntax near
the keyword 'WHERE'. at Connection.
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\lib\tedious.js:658:17)
at emitOne (events.js:116:13) at Connection.emit (events.js:211:7)
at Parser.
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\connection.js:444:15)
at emitOne (events.js:116:13) at Parser.emit (events.js:211:7) at
Parser.nextToken
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\token\token-stream-parser.js:91:18)
at Parser.addBuffer
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\token\token-stream-parser.js:68:17)
at Connection.sendDataToTokenStreamParser
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\connection.js:891:35)
at Connection.data
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\connection.js:275:23)
at Connection.dispatchEvent
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\connection.js:752:59)
at MessageIO.
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\connection.js:680:22)
at emitOne (events.js:116:13) at MessageIO.emit (events.js:211:7)
at MessageIO.eventData
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\message-io.js:56:12)
at Socket.
(D:\Project\WODevelopment\trunk\QMS3.0\POC\WideOrbit-Server\node_modules\sails-sqlserver\node_modules\mssql\node_modules\tedious\lib\message-io.js:3:59)
at emitOne (events.js:116:13) at Socket.emit (events.js:211:7) at
addChunk (_stream_readable.js:263:12) at readableAddChunk
(_stream_readable.js:250:11) at Socket.Readable.push
(_stream_readable.js:208:10) at TCP.onread (net.js:594:20)
Details: RequestError: Incorrect syntax near the keyword 'WHERE'.

Firstly try to use sails-mssql and if does not resolves your problem then go for below
Sails uses do not provide any specific method to debug query generate and executed with waterline Orm
Here are few method listed below to debug the problem more efficiently as the error stack say their is a problem in query near Where clause
2018-03-21T08:21:52.868Z - error: error: Error (E_UNKNOWN) :: Encountered an
unexpected error RequestError: Incorrect syntax near the keyword 'WHERE'. at
Connection.
1) Use these method to debug mssql management studio query log with
How to see query history in SQL Server Management Studio
2) Try to get to the driver of mssql > core file where it execute query and do console.log
hope it helps you

Related

hyperledger-explorer can not connect to provisioned Postgres instance on IBM Cloud

I'm trying to connect hyperledger-explorer to IBM Cloud Databases for Postgres instance. I provide the correct credentials to connect to DB. However, the app gives authentication errors.
[2021-08-19T10:38:01.088] [ERROR] PgService - error when connecting to db: error: no pg_hba.conf entry for host "172.30.229.241", user "ibm_cloud_a55353b8_7766_4dbb_9c6b_89ee7b666773", database "ibmclouddb", SSL off
at Connection.parseE (/opt/explorer/node_modules/pg/lib/connection.js:614:13)
at Connection.parseMessage (/opt/explorer/node_modules/pg/lib/connection.js:413:19)
at Socket.<anonymous> (/opt/explorer/node_modules/pg/lib/connection.js:129:22)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:273:9)
at Socket.Readable.push (_stream_readable.js:214:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
From inside the explorer pod, I installed psql -for investigation- and tried to connect to my instance using
PGPASSWORD=xxx psql 'host=xxx po
rt=xxx dbname=ibmclouddb user=ibm_cloud_user'
and it works, I was able to connect to the DB.
I'm sure the application uses incorrect connection strings to DB. But, I can't see what it sends to verify
any idea how can I resolve this?

'MongoError: setName from ismaster does not match provided connection setName' when trying to connect to a MongoDB cluster using mongoose

I am student trying to build a restful API for a project. I am very new to this so please excuse me if it is an easy fix.
I am using "mongoose": "^5.3.4", and trying to connect to a cluster named '128project' in Mongo DB Atlas 3.6.8.
Here is the snippet I am using to connect:
mongoose.connect( uri ,{ useNewUrlParser: true }).catch(function (reason) {
console.log('error ', reason);
});
The URI I am using is exactly what the Mongo Atlas DB provided.
I get this in the terminal:
error { MongoError: setName from ismaster does not match provided connection setName [128project-shard-0] != [128]
at ReplSetState.update (C:\Users\TAHP TAHP TAHP\Desktop\128test\node_modules\mongodb-core\lib\topologies\replset_state.js:403:14)
at C:\Users\TAHP TAHP TAHP\Desktop\128test\node_modules\mongodb-core\lib\topologies\replset.js:809:45
at applyAuthenticationContexts (C:\Users\TAHP TAHP TAHP\Desktop\128test\node_modules\mongodb-core\lib\topologies\replset.js:731:12)
at Server.<anonymous> (C:\Users\TAHP TAHP TAHP\Desktop\128test\node_modules\mongodb-core\lib\topologies\replset.js:802:7)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at Server.emit (events.js:211:7)
at C:\Users\TAHP TAHP TAHP\Desktop\128test\node_modules\mongodb-core\lib\topologies\server.js:508:16
at C:\Users\TAHP TAHP TAHP\Desktop\128test\node_modules\mongodb-core\lib\connection\pool.js:532:18
at _combinedTickCallback (internal/process/next_tick.js:132:7)
at process._tickCallback (internal/process/next_tick.js:181:9) name: 'MongoError', [Symbol(mongoErrorContextSymbol)]: {} }
Any feedback is appreciated!
For the sake of completion - this happened to me as well when connecting to MongoDB 4.2 ReplicaSet. I removed the replicaSet=some_name part from the URI and it worked.
It's a known issue for some drivers, see this too.
What's the uri which you want to connect, it must be like this format
mongodb://username:password#10.0.0.298,10.0.1.299/db_name?replicaSet=replSetName

sails Sorry, this function doesn't know how to handle {...} callbacks

Somehow, my sails.js 1.x environment has gotten mangled to the point that I'm no longer able to do native queries to my PostgreSQL database. I'm sure the issue is the version of some package or another, because I did some experimentation with NodeJS 9 over the weekend, but this code was working on Friday and I can't seen to find the issue. Any suggestions?
sails> sails.getDatastore().sendNativeQuery('SELECT COUNT(*) FROM "user"').then(console.log);
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
sails> UsageError: Sorry, this function doesn't know how to handle {...} callbacks.
If provided, the 2nd argument should be a function like `function(err,result){...}`
| If you passed in {...} on purpose as a "switchback" (dictionary of callbacks),
| please be aware that, as of machine v15, you can no longer pass in a switchback
| as the 2nd argument. And you can't pass a switchback in to .exec() anymore either.
| Instead, you'll need to explicitly call .switch().
[?] See https://sailsjs.com/support for help.
at /Users/patrick/src/healthcelerate/hc-registry/node_modules/sails-hook-orm/lib/datastore-method-utils/private/do-with-connection.js:133:24
at _makeCallToDuringFn (/Users/patrick/src/healthcelerate/hc-registry/node_modules/sails-hook-orm/lib/datastore-method-utils/private/do-with-connection.js:101:28)
at /Users/patrick/src/healthcelerate/hc-registry/node_modules/sails-hook-orm/lib/datastore-method-utils/private/do-with-connection.js:103:7
at /Users/patrick/src/healthcelerate/hc-registry/node_modules/sails-hook-orm/lib/datastore-method-utils/private/do-with-connection.js:66:14
at /Users/patrick/src/healthcelerate/hc-registry/node_modules/machinepack-postgresql/node_modules/machine/lib/private/help-build-machine.js:966:24
at Function.handlerCbs.success (/Users/patrick/src/healthcelerate/hc-registry/node_modules/machinepack-postgresql/node_modules/machine/lib/private/help-build-machine.js:826:26)
at cb (/Users/patrick/src/healthcelerate/hc-registry/node_modules/machinepack-postgresql/machines/get-connection.js:87:20)
at BoundPool.<anonymous> (/Users/patrick/src/healthcelerate/hc-registry/node_modules/pg-pool/index.js:137:9)
at bound (domain.js:301:14)
at runBound (domain.js:314:12)
at /Users/patrick/src/healthcelerate/hc-registry/node_modules/generic-pool/lib/generic-pool.js:347:9
at BoundPool.<anonymous> (/Users/patrick/src/healthcelerate/hc-registry/node_modules/pg-pool/index.js:103:7)
at Connection.<anonymous> (/Users/patrick/src/healthcelerate/hc-registry/node_modules/pg/lib/client.js:158:7)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:121:20)
at Connection.emit (events.js:211:7)
at Socket.<anonymous> (/Users/patrick/src/healthcelerate/hc-registry/node_modules/pg/lib/connection.js:121:12)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:607:20)
sails>
Any tips or ideas would be much apprviated.
This turned out to be a bug in the version of Sails we were running. I upgraded sails to 1.0.2 and it resolved.

SequelizeHostNotFoundError on Cloud functions

I am trying to run sequelize on Google Cloud functions, and trying to connect to a remote db hosted on compose.com, but I am getting this error
`
SequelizeHostNotFoundError: getaddrinfo ENOTFOUND gcp-us-east1-
cpu.2.dblayer.com gcp-us-east1-cpu.2.dblayer.com:16070
at connection.connect.err
(/user_code/node_modules/sequelize/lib/dialects/postgres/connection-
manager.js:95:24)
at Client.<anonymous>
(/user_code/node_modules/pg/lib/client.js:203:5)
at emitOne (events.js:96:13)
at Connection.emit (events.js:188:7)
at Socket.<anonymous>
(/user_code/node_modules/pg/lib/connection.js:86:10)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at connectErrorNT (net.js:1020:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
`
Any ideas what I might be doing wrong?
I found the problem.
I couldn't connect to an external API or address if I wasn't subscribed to a paid plan on Google Cloud Functions.

Trouble using Amazon EC2 for remote Mongo database.

I have a multi-page mean.js app, that I need to host. I've tried the steps in this guide https://scotch.io/tutorials/deploying-a-mean-app-to-amazon-ec2-part-2 but when I try to run a local version of my app using a remote version of mongodb on an amazon EC2 instance, I run into the following error.
C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:246
throw message;
^
Error: Error setting TTL index on collection : sessions
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\connect-mongo\lib\connect-mongo.js:169:23
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1499:46
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1632:20
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\command_cursor.js:152:16
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1196:16
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1905:9
at Server.Base._callHandler (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:453:41)
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:488:18
at MongoReply.parseBody (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\responses\mongo_reply.js:68:5)
at null.<anonymous> (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:446:20)
at emit (events.js:107:17)
at null.<anonymous> (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:207:13)
at emit (events.js:110:17)
at Socket.<anonymous> (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection.js:440:22)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
In terms of my code, the only thing I've changed is replacing the line
module.exports = {
db: 'mongodb://localhost/borowr-dev',
with
module.exports = {
db: 'mongodb://MY_EC2_URL.com:27017/borowr-dev',
I previously tried updating my version of connect-mongo from 0.4.2 to 1.1.0, which caused other problems. Any help is appreciated, thanks.