Giter Site home page Giter Site logo

Comments (6)

smanask avatar smanask commented on June 12, 2024 2

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.

abisao1 avatar abisao1 commented on June 12, 2024 2

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.

Ejayz avatar Ejayz commented on June 12, 2024 1

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 ?
image
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.

Ejayz avatar Ejayz commented on June 12, 2024 1

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.

abisao1 avatar abisao1 commented on June 12, 2024

Hi is this problem solved ? I am also using nextjs with seperate db.ts file and i just call this file

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 ? image 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.

wellwelwel avatar wellwelwel commented on June 12, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.