How to use the mssql.globalConnectionPool function in mssql

To help you get started, we’ve selected a few mssql examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github erickangMSFT / sqldevops / web_app / src / routes / queryperf.js View on Github external
const express = require('express');
const router = express.Router();
const mssql = require('mssql');
const fs = require('fs');

const sqldevops = require('../modules/sqldevops.js');

const sqlFile = './src/sql/queryperf.sql';
const dbconfig = require('../config/dbconfig.json');
const nav = require('../config/navconfig.json');

const viewName = 'queryperf';
const title = 'Query Performance';

const pool = mssql.globalConnectionPool;
/* GET directory page. */
router.get('/', (req, res, next) => {
    fs.readFile(sqlFile, 'utf8', (err, script) => {
        const request = new mssql.Request(pool);
        request.query(script, (err, rec) => {
            if (err) {
                const sqlerror = sqldevops.getSqlError(err);
                res.render('error', {
                    message: sqlerror.message,
                    error: sqlerror
                });
            }
            else {
                // for debugging
                // console.log(rec.recordset);
                res.render(viewName, {
github erickangMSFT / sqldevops / web_app / src / routes / users.js View on Github external
const express = require('express');
const router = express.Router();
const mssql = require('mssql');
const fs = require('fs');

const sqldevops = require('../modules/sqldevops.js');

const sqlFile = './src/sql/users.sql';
const dbconfig = require('../config/dbconfig.json');
const nav = require('../config/navconfig.json');

const viewName = 'users';
const title = 'Database Users';

const pool = mssql.globalConnectionPool;

/* GET directory page. */
router.get('/', (req, res, next) => {
    fs.readFile(sqlFile, 'utf8', (err, script) => {
        const request = new mssql.Request(pool);
        request.query(script, (err, rec) => {
            if (err) {
                const sqlerror = sqldevops.getSqlError(err);
                res.render('error', {
                    message: sqlerror.message,
                    error: sqlerror
                });
            }
            else {
                // for debugging
                // console.log(rec.recordset);
github erickangMSFT / sqldevops / web_app / src / routes / directory.js View on Github external
// Author: Eric Kang
// License: MIT
// ------------------------------------------------------------------------//

'use strict';

const express = require('express');
const router = express.Router();
const mssql = require('mssql');
const fs = require('fs');
const sqldevops = require('../modules/sqldevops.js');

const dbconfig = require('../config/dbconfig.json');
const directorySqlFile = './src/sql/customers_wwi.sql';
const nav = require('../config/navconfig.json');
const pool = mssql.globalConnectionPool;
/* GET directory page. */
router.get('/', (req, res, next) => {
    fs.readFile(directorySqlFile, 'utf8', (err, script) => {
        pool.connect((err) => {
            const request = new mssql.Request(pool);
            request.query(script, (err, rec) => {
                if (err) {
                    const sqlerror = sqldevops.getSqlError(err);
                    res.render('error', {
                        message: sqlerror.message,
                        error: sqlerror
                    });
                }
                else {
                    // for debugging
                    // console.log(rec.recordset);
github erickangMSFT / sqldevops / web_app / app.js View on Github external
// ------------------------------------------------------------------------//

'use strict';

const express = require('express');
const path = require('path');
const favicon = require('serve-favicon');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');

//database
const mssql = require('mssql');
const dbconfig = require('./src/config/dbconfig.json');
const pool = new mssql.ConnectionPool(dbconfig);
mssql.globalConnectionPool = pool;
//open database connection
pool.connect((err)=>{
  if (err){
    console.log('connection failed to server:' + dbconfig.server + ' database:' + dbconfig.database);
    console.log(err);
  }
  else {
    console.log ('Connected to ' + dbconfig.server 
                    + '/' + dbconfig.database 
                    + ' (' + dbconfig.user + ')');
    const request = new mssql.Request(pool);
    request.query('select @@version',(err,rec)=>{
      console.log(JSON.stringify(rec.recordset, null, 0)
        .replace('[{"":"', '')
        .replace('"}]','')
      );
github erickangMSFT / sqldevops / web_app / src / routes / servermemorybydb.js View on Github external
const express = require('express');
const router = express.Router();
const mssql = require('mssql');
const fs = require('fs');

const sqldevops = require('../modules/sqldevops.js');

const sqlFile = './src/sql/servermemorybydb.sql';
const dbconfig = require('../config/dbconfig.json');
const nav = require('../config/navconfig.json');

const viewName = 'servermemorybydb';
const title = 'Memory Usage by Database';

const pool = mssql.globalConnectionPool;

/* GET directory page. */
router.get('/', (req, res, next) => {
    fs.readFile(sqlFile, 'utf8', (err, script) => {
        const request = new mssql.Request(pool);
        request.query(script, (err, rec) => {
            if (err) {
                const sqlerror = sqldevops.getSqlError(err);
                res.render('error', {
                    message: sqlerror.message,
                    error: sqlerror
                });
            }
            else {
                // for debugging
                // console.log(rec.recordset);
github erickangMSFT / sqldevops / web_app / src / routes / backuphistory.js View on Github external
const express = require('express');
const router = express.Router();
const mssql = require('mssql');
const fs = require('fs');

const sqldevops = require('../modules/sqldevops.js');

const sqlFile = './src/sql/backuphistory.sql';
const dbconfig = require('../config/dbconfig.json');
const nav = require('../config/navconfig.json');

const viewName = 'backuphistory';
const title = 'Backup History';
const description = 'Backup history for all databases.';

const pool = mssql.globalConnectionPool;

/* GET directory page. */
router.get('/', (req, res, next) => {
    fs.readFile(sqlFile, 'utf8', (err, script) => {
        const request = new mssql.Request(pool);
        request.query(script, (err, rec) => {
            if (err) {
                const sqlerror = sqldevops.getSqlError(err);
                res.render('error', {
                    message: sqlerror.message,
                    error: sqlerror
                });
            }
            else {
                // for debugging
                // console.log(rec.recordset);
github erickangMSFT / sqldevops / web_app / src / routes / index.js View on Github external
// License: MIT
// ------------------------------------------------------------------------//

'use strict';

const express = require('express');
const router = express.Router();
const mssql = require('mssql');
const fs = require('fs');
const sqldevops = require('../modules/sqldevops.js');

const dbconfig = require('../config/dbconfig.json');
const tablespaceSqlFile = './src/sql/tablespace.sql';
const nav = require('../config/navconfig.json');

const pool = mssql.globalConnectionPool;

/* GET home page. */
router.get('/', (req, res, next) => {
  fs.readFile(tablespaceSqlFile, 'utf8', (err, script) => {
    pool.connect((err) => {
      const request = new mssql.Request(pool);
      request.query(script, (err, rec) => {
        if (err) {
          const sqlerror = sqldevops.getSqlError(err);
          res.render('error', {
            message: sqlerror.message,
            error: sqlerror
          });
        }
        else {
          // for debugging
github erickangMSFT / sqldevops / web_app / src / routes / tablespacedetail.js View on Github external
// ------------------------------------------------------------------------//

'use strict';

const express = require('express');
const router = express.Router();
const mssql = require('mssql');
const fs = require('fs');

const sqldevops = require('../modules/sqldevops.js');

const dbconfig = require('../config/dbconfig.json');
const tablespaceSqlFile = './src/sql/tablespace.sql';
const nav = require('../config/navconfig.json');

const pool = mssql.globalConnectionPool;

/* GET home page. */
router.get('/', (req, res, next) => {
  const request = new mssql.Request(pool);
  fs.readFile(tablespaceSqlFile, 'utf8', (err, script) => {
    const request = new mssql.Request(pool);
    request.query(script, (err, rec) => {
      if (err) {
        const sqlerror = sqldevops.getSqlError(err);
        res.render('error', {
          message: sqlerror.message,
          error: sqlerror
        });
      }
      else {
        // for debugging