Comments (6)
In the finally block, you are calling dbConnection.end, but it seems like there's a missing pair of parentheses (). It should be dbConnection.end() to actually invoke the method.
The correct code should be:
finally {
// Terminate connection to the database
dbConnection.end();
}
Without them, it won't execute the method and the database connections may not be closed correctly, leading to "Too many connections".
You might also consider using pooling to manage database connections, especially in scenarios with multiple concurrent requests.
from node-mysql2.
In the finally block, you are calling dbConnection.end, but it seems like there's a missing pair of parentheses (). It should be dbConnection.end() to actually invoke the method.
The correct code should be:
finally { // Terminate connection to the database dbConnection.end(); }Without them, it won't execute the method and the database connections may not be closed correctly, leading to "Too many connections".
You might also consider using pooling to manage database connections, especially in scenarios with multiple concurrent requests.
The issue has been resolved. Thank thank you for the heads-up.
from node-mysql2.
Hi is this problem solved ? I am also using nextjs with seperate db.ts
file and i just call this file
"use strict";
import mysql from "mysql2/promise";
import * as dotenv from "dotenv";
dotenv.config();
const { DB_HOST, DB_USER, DB_PASSWORD, DB_NAME } = process.env;
const Connection=async ()=>{
return mysql.createConnection({
host: DB_HOST,
user: DB_USER,
password: DB_PASSWORD,
database: DB_NAME,
waitForConnections: true,
connectionLimit: 10,
idleTimeout: 5000,
queueLimit: 0,
});
}
Connection().then((res)=>{
console.log(res)
}
).catch((err)=>{
console.log(err)
})
console.log( Connection());
export default Connection;
But getting error too of too many connection after several queries . Have you checked the process and connection stats of your mysql if proccesses are being stopped ?
as you can see in the image it keeps on increasing the process but it is true that the connection is dropped . Will this be about me importing the db.ts
file?
from node-mysql2.
Hi is this problem solved ? I am also using nextjs with seperate db.ts file and i just call this file
@Ejayz, it looks like you're already following this thread on #2362 🕵🏻
Both actually lol. But yea . my issue is fixed also .
from node-mysql2.
Hi is this problem solved ? I am also using nextjs with seperate
db.ts
file and i just call this fileimport mysql from "mysql2/promise"; import * as dotenv from "dotenv"; dotenv.config(); const { DB_HOST, DB_USER, DB_PASSWORD, DB_NAME } = process.env; const Connection=async ()=>{ return mysql.createConnection({ host: DB_HOST, user: DB_USER, password: DB_PASSWORD, database: DB_NAME, waitForConnections: true, connectionLimit: 10, idleTimeout: 5000, queueLimit: 0, }); } Connection().then((res)=>{ console.log(res) } ).catch((err)=>{ console.log(err) }) console.log( Connection()); export default Connection;
But getting error too of too many connection after several queries . Have you checked the process and connection stats of your mysql if proccesses are being stopped ? as you can see in the image it keeps on increasing the process but it is true that the connection is dropped . Will this be about me importing the
db.ts
file?
Yes it has been resolved. Thanks!
from node-mysql2.
Hi is this problem solved ? I am also using nextjs with seperate db.ts file and i just call this file
@Ejayz, it looks like you're already following this thread on #2362 🕵🏻
from node-mysql2.
Related Issues (20)
- HANDSHAKE_SSL_ERROR with RDS and 3.9.3+ HOT 12
- Can't create more than max prepared stmtount statements(current value: 16382) HOT 4
- Release 3.9.4 breaks code that depended on .hasOwnProperty() HOT 3
- got warning when host is an IP address HOT 3
- Transaction issue in my code. Please Help!
- read ECONNRESET after upgrading HOT 11
- typeCast: false causes out of bounds reads to packet when result set contains NULL values and binary protocol is used.
- README documentation HOT 1
- True negative: ssl-mode query params in connectionString considered as invalid HOT 1
- TypeError: LRU is not a constructor HOT 3
- PoolConnection.execute() retrun object v3.9.7 HOT 6
- Deadlock found when trying to get lock HOT 3
- [createConnection] Can't add new command when connection is in closed state HOT 8
- Sporadic read ETIMEDOUT error HOT 9
- Incorrect typings lead to pool.destroy is not a function HOT 2
- Invalid ssl option but still DB connection working fine HOT 1
- Access Denied after database restart (but granted after login via CLI) HOT 23
- Importing mysql2 causes source maps not working in project bundled with webpack HOT 7
- DELIMITER causes syntax error
- Building query for ORDER BY ? DESC/ASC doesn't seem to use the values HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-mysql2.