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.

clarify connection pooling

See original GitHub issue

Regarding connection pooling… if I request a new sql.Connection(cfg) (more than once) will it return a connection from the same pool (based on cfg options), or will it create a new pool?

Regarding v2 (Promises based) if the above isn’t the behavior, could it be made to be the behavior internally? I’m doing something similar to the following, but if I could just have the same connection from a pool, that would be awesome.

https://gist.github.com/tracker1/5ad0bff295369ac05eea

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:21 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
tracker1commented, Apr 9, 2015

@mbrio - mssql’s connection is always a pool…

I usually do something like…

//getConnection module
var conOptions = require('../config/sql'); //store your connection options wherever
var mssql = require('mssql');
var Promise = require('i-promise'); //use whatever promise library you like
var cp = null;
module.exports = getConnection;

function getConnection(){
  if (cp) return cp;
  return cp = new Promise(function(resolve,reject){
    var conn = new mssql.Connection(conOptions, function(err){
      if (err){
        cp = null;
        return reject(err);
      }
      return resolve(conn);
    });
  });
}

Then from the outside…

var cp = require('../sql/get-connection');
...
  cp.then(
    function(conn){
      //do something with connection
      var request = new mssql.Request(conn);
    },
    function(err){
      console.error(err);
      process.exit(666);
    }
  )
...

there’s also… connection.connect() but I’m not sure if it will resolve the actual connection… in my case, the same promise/connection will always be returned, and it is indeed a pool.

1reaction
benjaminmbrowncommented, May 23, 2017

This is one of my favorite GH issues I’ve come across - good questions on a tricky subject and great answers with usable examples. Helped me out a ton! Thx guys

Read more comments on GitHub >

github_iconTop Results From Across the Web

Connection Pooling in Java - DigitalOcean
Connection pooling means a pool of Connection Objects. Connection pooling is based on an object pool design pattern. Object pooling design ...
Read more >
Documentation: Clarify how a Connection Pool works #2260
Most databases connectors make use of the term "ConnectionPool" to describe a pool of connections that are held open to the database that...
Read more >
A Simple Guide to Connection Pooling in Java - Baeldung
Connection pooling is a well-known data access pattern. Its main purpose is to reduce the overhead involved in performing database ...
Read more >
JDBC Connection Pools - Oracle Help Center
A connection pool contains a group of JDBC connections that are created when the connection pool is registered—when starting up WebLogic Server or...
Read more >
What Is Connection Pooling - YouTube
Differnce between DataSet. · ADO.NET Connection Pooling | ADO.NET Interview Questions | Connection Pooling in C# · Connection Pool with an Oracle ...
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