Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const config = {
- nConnection:'conexion1',
- user: 'usuario_node',
- password: 'node123',
- server: '127.0.0.1', // You can use 'localhost\\instance' to connect to named instance
- database: 'pruebas_node',
- port: '1433',
- connectionTimeout:1000 ,
- options: {
- trustedConnection: true
- },
- parseJSON: true
- }
- const configs = {principal:{nConnection:'principal',
- user: 'usuario_node',
- password: 'node123',
- server: '127.0.0.1', // You can use 'localhost\\instance' to connect to named instance
- database: 'pruebas_node',
- port: '1433',
- connectionTimeout:1000 ,
- options: {
- trustedConnection: true
- },
- parseJSON: true
- },
- secundaria:{
- nConnection:'secundaria',
- user: 'usuario_node',
- password: 'node123',
- server: '127.0.0.1', // You can use 'localhost\\instance' to connect to named instance
- database: 'pruebas ',
- port: '1433',
- connectionTimeout:1000 ,
- options: {
- trustedConnection: true
- },
- parseJSON: true
- }};
- var sql = require('mssql')
- function getConnectionPoolGlobal(config){
- function Connect(resolve,reject){
- if (global.poolGlobal[config.nConnection]){
- console.log('Reutilizando pool '+config.nConnection+','+poolGlobal[config.nConnection].listenerCount())
- // console.log(poolGlobal[config.nConnection])
- resolve(poolGlobal[config.nConnection])
- }
- else{
- new sql.ConnectionPool(config).connect().then(poolObt=>{
- global.poolGlobal[config.nConnection]=poolObt
- resolve(global.poolGlobal[config.nConnection])
- console.log('Nuevo pool Creado')
- }).catch(err =>{
- reject(err)
- })
- }
- }
- return new Promise(Connect)
- }
- module.exports={
- config,
- getConnectionPoolGlobal,
- configs
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement