question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Initial successfull connecction callback for connecton pooling (DOCS update)

See original GitHub issue

Hi

var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : 'example.org',
  user     : 'bob',
  password : 'secret'
});
 
connection.connect(function(err) {
  if (err) {
    console.error('error connecting: ' + err.stack);
    return;
  }
 
  console.log('connected as id ' + connection.threadId);
});

with the above code for connections creation we can print successfully connected message initially to indicate the the db is connected

How to do the same when we create a new pool and want to know that the server successfully connected before executing any queries …

var mysql = require('mysql');
var pool  = mysql.createPool(...);
 

how to print the initial connected to db message with this…

If there is a way please add it to docs, it will be very useful indicate the successful db connection.

Thank You !

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dougwilsoncommented, Aug 13, 2021

You could execute a query, or even just call getConnection and then release it back if you want. Usually checking that on start is a bit of an antipattern, though, as it can stop connecting right at any point after your app started.

1reaction
dougwilsoncommented, Aug 13, 2021

The pool will emit a connection event when a new connection is made within the pool. Creating the pool won’t create a connection until you ask it for a connection.

Read more comments on GitHub >

github_iconTop Results From Across the Web

17 Tuning Data Source Connection Pools - Oracle Help Center
This chapter provides information on how to properly tune the connection pool attributes in JDBC data sources in your WebLogic Server 12.1.3 domain...
Read more >
psycopg_pool – Connection pool implementations
The NullConnectionPool is a ConnectionPool subclass which doesn't create connections preemptively and doesn't keep unused connections in its state. See Null ...
Read more >
Connecting and disconnecting (Concepts) - Prisma
This page explains how database connections are handled with Prisma Client and how to manually connect and disconnect your database.
Read more >
Connecting to Oracle Database - cx_Oracle's documentation!
A connection pool is created by calling SessionPool() . This is generally called during application initialization. The initial pool size and ...
Read more >
SQL Server Connection Pooling - ADO.NET - Microsoft Learn
When a connection is first opened, a connection pool is created based on an exact matching algorithm that associates the pool with the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found