This error came up when I tried running server. what should I do?
(node:6856) DeprecationWarning: current URL string parser is
deprecated, and will be removed in a future version. To use the new
parser, pass option { useNewUrlParser: true } to MongoClient.connect.
Server running on port ${port} { MongoNetworkError: failed to connect
to server [ds263172.mlab.com:63172] on first connect
[MongoNetworkError: connect ETIMEDOUT 54.171.245.223:63172] at
Pool. (D:\Learning &
Interest\Computer\Web\projects\devconnector\node_modules\mongodb-core\lib\topologies\server.js:564:11)
at emitOne (events.js:116:13) at Pool.emit (events.js:211:7) at
Connection. (D:\Learning &
Interest\Computer\Web\projects\devconnector\node_modules\mongodb-core\lib\connection\pool.js:317:12)
at Object.onceWrapper (events.js:317:30) at emitTwo (events.js:126:13)
at Connection.emit (events.js:214:7) at Socket.
(D:\Learning &
Interest\Computer\Web\projects\devconnector\node_modules\mongodb-core\lib\connection\connection.js:246:50)
at Object.onceWrapper (events.js:315:30) at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7) at emitErrorNT
(internal/streams/destroy.js:66:8) at _combinedTickCallback
(internal/process/next_tick.js:139:11) at process._tickCallback
(internal/process/next_tick.js:181:9) name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
On your MongoClient.connect(...) statement add {useNewParser: true}. Your connect statement should look something like this:
MongoClient.connect("mongodb://localhost:27017/YourDB", { useNewUrlParser: true })
As the warning suggests you need to use the updated URL parser
USE this for Reference
Related
I'm using the MySQL module for NodeJS, however I keep getting the following error after approximately 10 requests to the database. I'm using the following code to connect to the DB:
var con = mysql.createConnection({
host: "10.37.100.15",
user: process.env.MYSQLUSR,
password: process.env.MYSQLPASSWD,
database: process.env.MYSQLDB
});
Then I use con.query(sqlStatement, function (err, result, fields) {<function>}). I already tried changing the max_allowed_packet to 500M on the server but this didn't fix the issue. This is the full error:
events.js:377
throw er; // Unhandled 'error' event
^
Error: Packets out of order. Got: 0 Expected: 3
at Parser._tryReadPacketHeader (/app/node_modules/mysql/lib/protocol/Parser.js:470:15)
at Parser.write (/app/node_modules/mysql/lib/protocol/Parser.js:33:29)
at Protocol.write (/app/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:88:28)
at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:526:10)
at Socket.emit (events.js:400:28)
at addChunk (internal/streams/readable.js:293:12)
at readableAddChunk (internal/streams/readable.js:267:9)
at Socket.Readable.push (internal/streams/readable.js:206:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
Emitted 'error' event on Connection instance at:
at Connection._handleProtocolError (/app/node_modules/mysql/lib/Connection.js:423:8)
at Protocol.emit (events.js:400:28)
at Protocol._delegateError (/app/node_modules/mysql/lib/protocol/Protocol.js:398:10)
at Protocol.handleParserError (/app/node_modules/mysql/lib/protocol/Protocol.js:380:10)
at Parser._tryReadPacketHeader (/app/node_modules/mysql/lib/protocol/Parser.js:478:10)
at Parser.write (/app/node_modules/mysql/lib/protocol/Parser.js:33:29)
[... lines matching original stack trace ...]
at Socket.emit (events.js:400:28) {
code: 'PROTOCOL_PACKETS_OUT_OF_ORDER',
fatal: true
}
default wait_timeout is 8 hrs.
I'd suspect the mysql-nodejs version isn't resetting the expected packet count on re-connection.
In a test environment you can reduce the wait_timeout.
It quite possibly is:
https://github.com/mysqljs/mysql/issues/2534
https://github.com/mysqljs/mysql/issues/2451
Last comment on #2534 is "I change my connection from mysql.createConnection to mysql.createPool, the error never happen again"
i have a node application that is duplicated both on the server (digital ocean) as well as my local machine. im trying to configure the local version so that i can use it as a 'sandbox' environment to make changes and edits before i push the update to the live application on the server.
the databaseconnection.js file contains the following.
const mysql = require('mysql');
function getConnection() {
return mysql.createPool({
connectionLimit: 100,
host: 'ipaddress',
port: 3306,
user: 'forge',
password: 'password',
database: 'mydatabase',
multipleStatements: true
});
}
module.exports = getConnection();
when i access the node application that is stored on the DO server, everything run fine, however, when i try to run it from my localhost environment, i get the following error.
Error: connect ETIMEDOUT
at PoolConnection.Connection._handleConnectTimeout (C:\MAMP\htdocs\WIGHTcloudDEV\node_modules\mysql\lib\Connection.js:409:13)
at Object.onceWrapper (events.js:286:20)
at Socket.emit (events.js:198:13)
at Socket._onTimeout (net.js:442:8)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
--------------------
at Protocol._enqueue (C:\MAMP\htdocs\WIGHTcloudDEV\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\MAMP\htdocs\WIGHTcloudDEV\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at PoolConnection.connect (C:\MAMP\htdocs\WIGHTcloudDEV\node_modules\mysql\lib\Connection.js:116:18)
at Pool.getConnection (C:\MAMP\htdocs\WIGHTcloudDEV\node_modules\mysql\lib\Pool.js:48:16)
at Pool.query (C:\MAMP\htdocs\WIGHTcloudDEV\node_modules\mysql\lib\Pool.js:202:8)
at Strategy.passport.use.OutlookStrategy [as _verify] (C:\MAMP\htdocs\WIGHTcloudDEV\config\passport-setup.js:58:18)
at C:\MAMP\htdocs\WIGHTcloudDEV\node_modules\passport-oauth2\lib\strategy.js:202:24
at Request._callback (C:\MAMP\htdocs\WIGHTcloudDEV\node_modules\passport-outlook\lib\strategy.js:157:5)
at Request.self.callback (C:\MAMP\htdocs\WIGHTcloudDEV\node_modules\request\request.js:185:22)
at Request.emit (events.js:198:13)
i slightly remember doing something with either ssh2 or tunnel forwarder in the past that pertained to this issue but i cant find any of my old files nor can i find anything online that clearly shows what im missing.
Similar issues have been reported, but I can't work around with there solutions.
I have an express.js app using KNEX to connect to a mysql database hosted in Azure.
I can connect to the DB perfectly from console command or mysql workbench.
However, no way to achieve the same from my node app.
My connection object is the same though:
config.knex = require('knex')({
client: 'mysql',
connection: {
host: 'wineserver.mysql.database.azure.com',
user: 'BurgerAndGreenBeans#wineserver',
password: 'FromageDeChevre',
database: 'gdpr',
insecureAuth: true
},
pool: {
min: 0
},
debug: ['ComQueryPacket']
});
Everytime I start the app, I get alternatively either one error or another one:
#1
Unhandled rejection Error: read ECONNRESET
at exports._errnoException (util.js:1050:11)
at TCP.onread (net.js:582:26)
--------------------
at Protocol._enqueue (C:\Projects\gdpr\node_modules\mysql\lib\protocol\Protocol.js:141:48)
at Protocol.handshake (C:\Projects\gdpr\node_modules\mysql\lib\protocol\Protocol.js:52:41)
at Connection.connect (C:\Projects\gdpr\node_modules\mysql\lib\Connection.js:130:18)
at C:\Projects\gdpr\node_modules\knex\lib\dialects\mysql\index.js:106:18
at Promise._execute (C:\Projects\gdpr\node_modules\bluebird\js\release\debuggability.js:300:9)
at Promise._resolveFromExecutor (C:\Projects\gdpr\node_modules\bluebird\js\release\promise.js:483:18)
at new Promise (C:\Projects\gdpr\node_modules\bluebird\js\release\promise.js:79:10)
at Client_MySQL.acquireRawConnection (C:\Projects\gdpr\node_modules\knex\lib\dialects\mysql\index.js:104:12)
at Object.create (C:\Projects\gdpr\node_modules\knex\lib\client.js:239:16)
at Pool._createResource (C:\Projects\gdpr\node_modules\generic-pool\lib\generic-pool.js:354:17)
at Pool.dispense [as _dispense] (C:\Projects\gdpr\node_modules\generic-pool\lib\generic-pool.js:314:10)
at Pool.acquire (C:\Projects\gdpr\node_modules\generic-pool\lib\generic-pool.js:436:8)
at C:\Projects\gdpr\node_modules\knex\lib\client.js:289:19
at Promise._execute (C:\Projects\gdpr\node_modules\bluebird\js\release\debuggability.js:300:9)
at Promise._resolveFromExecutor (C:\Projects\gdpr\node_modules\bluebird\js\release\promise.js:483:18)
at new Promise (C:\Projects\gdpr\node_modules\bluebird\js\release\promise.js:79:10)
Process finished with exit code 0
or
#2
Unhandled rejection Error: ER_HANDSHAKE_ERROR: Bad handshake
at Handshake.Sequence._packetToError (C:\Projects\gdpr\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
at Handshake.ErrorPacket (C:\Projects\gdpr\node_modules\mysql\lib\protocol\sequences\Handshake.js:103:18)
at Protocol._parsePacket (C:\Projects\gdpr\node_modules\mysql\lib\protocol\Protocol.js:280:23)
at Parser.write (C:\Projects\gdpr\node_modules\mysql\lib\protocol\Parser.js:75:12)
at Protocol.write (C:\Projects\gdpr\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\Projects\gdpr\node_modules\mysql\lib\Connection.js:103:28)
at emitOne (events.js:96:13)
at Socket.emit (events.js:191:7)
at readableAddChunk (_stream_readable.js:178:18)
at Socket.Readable.push (_stream_readable.js:136:10)
at TCP.onread (net.js:561:20)
--------------------
at Protocol._enqueue (C:\Projects\gdpr\node_modules\mysql\lib\protocol\Protocol.js:141:48)
at Protocol.handshake (C:\Projects\gdpr\node_modules\mysql\lib\protocol\Protocol.js:52:41)
at Connection.connect (C:\Projects\gdpr\node_modules\mysql\lib\Connection.js:130:18)
at C:\Projects\gdpr\node_modules\knex\lib\dialects\mysql\index.js:106:18
at Promise._execute (C:\Projects\gdpr\node_modules\bluebird\js\release\debuggability.js:300:9)
at Promise._resolveFromExecutor (C:\Projects\gdpr\node_modules\bluebird\js\release\promise.js:483:18)
at new Promise (C:\Projects\gdpr\node_modules\bluebird\js\release\promise.js:79:10)
at Client_MySQL.acquireRawConnection (C:\Projects\gdpr\node_modules\knex\lib\dialects\mysql\index.js:104:12)
at Object.create (C:\Projects\gdpr\node_modules\knex\lib\client.js:239:16)
at Pool._createResource (C:\Projects\gdpr\node_modules\generic-pool\lib\generic-pool.js:354:17)
at Pool.dispense [as _dispense] (C:\Projects\gdpr\node_modules\generic-pool\lib\generic-pool.js:314:10)
at Pool.acquire (C:\Projects\gdpr\node_modules\generic-pool\lib\generic-pool.js:436:8)
at C:\Projects\gdpr\node_modules\knex\lib\client.js:289:19
at Promise._execute (C:\Projects\gdpr\node_modules\bluebird\js\release\debuggability.js:300:9)
at Promise._resolveFromExecutor (C:\Projects\gdpr\node_modules\bluebird\js\release\promise.js:483:18)
at new Promise (C:\Projects\gdpr\node_modules\bluebird\js\release\promise.js:79:10)
Process finished with exit code 0
It seems to be a kind of incompatibility between Node and Azure's mysql server.
Did anyone experienced the same ?
The similar question: Connecting to Azure Database for MySQL in npm/mysql. As #Gary Liu pointed out, you may use pull 1730 for a workaround.
Please modify the package.json as:
"dependencies": {
"knex": "^0.13.0",
"mysql": "git://github.com/mysqljs/mysql#e3e123e9af7c0829a6c1417d911572a75b4a5f95"
}
then, run npm install to install this version.
I am using Node-Webkit for creating desktop application using NodeJS.
In this i need to get data from MySQL database. For this am using node-mysql module and the following code is used to connect MySQL server using node-mysql.
var mysql_con = require('mysql');
var connection = mysql_con.createConnection({
host : input.host,
user : input.username,
password : input.password,
database : input.database
});
connection.connect(function(err) {
if (err) {
console.log('Error : '+err.stack);
}
console.log('Success');
});
if i run in the command line of my Windows machine, connection has been established and Success has been printed in console. But if i pack and run the code in the node-webkit's nw.exe its giving the following error in web console
Error : Error: ER_HANDSHAKE_ERROR: Bad handshake
at Handshake.Sequence._packetToError (C:\DOCUME~1\admin\LOCALS~1\Temp\nw4480_11607\node_modules\mysql\lib\protocol\sequences\Sequence.js:48:14)
at Handshake.ErrorPacket (C:\DOCUME~1\admin\LOCALS~1\Temp\nw4480_11607\node_modules\mysql\lib\protocol\sequences\Handshake.js:101:18)
at Protocol._parsePacket (C:\DOCUME~1\admin\LOCALS~1\Temp\nw4480_11607\node_modules\mysql\lib\protocol\Protocol.js:270:23)
at Parser.write (C:\DOCUME~1\admin\LOCALS~1\Temp\nw4480_11607\node_modules\mysql\lib\protocol\Parser.js:77:12)
at Protocol.write (C:\DOCUME~1\admin\LOCALS~1\Temp\nw4480_11607\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\DOCUME~1\admin\LOCALS~1\Temp\nw4480_11607\node_modules\mysql\lib\Connection.js:82:28)
at Socket.EventEmitter.emit (events.js:104:17)
at readableAddChunk (_stream_readable.js:156:16)
at Socket.Readable.push (_stream_readable.js:123:10)
at TCP.onread (net.js:520:20)
--------------------
at Protocol._enqueue (C:\DOCUME~1\admin\LOCALS~1\Temp\nw4480_11607\node_modules\mysql\lib\protocol\Protocol.js:135:48)
at Protocol.handshake (C:\DOCUME~1\admin\LOCALS~1\Temp\nw4480_11607\node_modules\mysql\lib\protocol\Protocol.js:52:41)
at Connection.connect (C:\DOCUME~1\admin\LOCALS~1\Temp\nw4480_11607\node_modules\mysql\lib\Connection.js:108:18)
at Object.mysql.testConnection
Kindly suggest me solution to establish the MySQL connection through node-webkit.
i had the same problem... and downgrading node webkit to the version 0.8.6 did the trick...
i hope this help you...
When trying to use sails-mysql I get an ER_NO_DB_ERROR: No database selected exception.
Even though I followed all the instructions I was able to find as closely as possible. I also looked into related issues:
Sailsjs - How to use mySQL
https://github.com/balderdashy/sails/issues/632
http://dustinbolton.com/error-er_no_db_error-no-database-selected/
Nothing seemed to help so far.
This is what I am doing:
I started out with a fresh project:
sails new sql-test
cd sql-test
Installed sails-mysql
sudo npm install sails-mysql
I changed the config:
// config/adapters.js
module.exports.adapters = {
'default': 'mysql',
mysql: {
module : 'sails-mysql',
host : 'localhost',
port : 3306,
user : 'root',
password : 'superSecret',
database : 'testDB'
}
};
Created a Model:
// api/models/User.js
module.exports = {
attributes: {
name: 'string'
}
};
And when I try to run it from the project's root:
sails lift
I get the following:
Logic error in mySQL ORM.
{ [Error: ER_NO_DB_ERROR: No database selected] code: 'ER_NO_DB_ERROR', index: 0 }
error: Hook failed to load: orm (Error: ER_NO_DB_ERROR: No database selected)
error: Error encountered while loading Sails core!
error: Error: ER_NO_DB_ERROR: No database selected
at Query.Sequence._packetToError (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:32:14)
at Query.ErrorPacket (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Query.js:82:18)
at Protocol._parsePacket (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:172:24)
at Parser.write (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Parser.js:62:12)
at Protocol.write (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:37:16)
at Socket.ondata (stream.js:51:26)
at Socket.EventEmitter.emit (events.js:117:20)
at Socket.<anonymous> (_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)
--------------------
at Query.Sequence (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:15:20)
at new Query (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Query.js:12:12)
at Function.Connection.createQuery (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/Connection.js:48:10)
at Connection.query (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/Connection.js:100:26)
at __DESCRIBE__ (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/lib/adapter.js:121:20)
at afterwards (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/lib/adapter.js:571:7)
at Handshake._callback (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/lib/adapter.js:549:9)
at Handshake.Sequence.end (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:66:24)
at Handshake.Sequence.OkPacket (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:75:8)
at Protocol._parsePacket (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:172:24)
at Parser.write (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Parser.js:62:12)
at Protocol.write (/home/tster/Documents/sandbox/sql-test/node_modules/sails-mysql/node_modules/mysql/lib/protocol/Protocol.js:37:16)
at Socket.ondata (stream.js:51:26)
at Socket.EventEmitter.emit (events.js:117:20)
at Socket.<anonymous> (_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)
Additional Information:
sails v0.9.13
sails-mysql (v0.9.9)
mysql v14.14 Distrib 5.5.34, for debian-linux-gnu (x86_64) using readline 6.2
I can connect the the database via command line.
I am able to connect and query the Database when using node-mysql
Could anybody give me some advice? Am I missing something? Anything else I should check out?
I just hit this same problem. In order to get it to work, I had to add the adapter configuration information to my model, e.g. /api/models/User.js:
module.exports = {
adapter: 'mysql',
config: {
host: 'localhost',
user: 'user',
port:'3306',
// Psst.. You can put your password in config/local.js instead
// so you don't inadvertently push it up if you're using version control
password: 'secret',
database: 'sailstest'
},
attributes: {
firstName: 'STRING'
}
};
See the docs:
http://sailsjs.org/#!documentation/models
I also had to add /api/controllers/UserController.js manually, as the generate function did not add it on this app, although it did add it on the previous test app I made.
UPDATE:
Install the Sails.js beta to get better functionality.
npm install sails#beta -g
Not only does the config actually work as expected (under config/connections.js), the ORM features support associations, which are not supported in the 0.9 release.
I know this question already has an answer, but it's more of a workaround. This is what fixed the same issue for me.
Changing the default adapters.js file mysql adapter object from myLocalMySQLDatabase to simply mysql seemed to fix it for me.
Hope this helps.
You may get this error when the .env file is not in the same directory.
You can check what the error is with the following code:
const result = require('dotenv').config();
if (result.error) {
console.log(result.error)
}
console.log(result.parsed)
You must take care about data type.
if you have module like this
module.exports = {
attributes: {
name: 'string'
}
};
In database under modal name table field name must be varchar.
My database field is set to text and I getting this error , when change it to varchar everything work.