javascript - node.js tedious ConnectionError: Failed to connect to sqlserverip:1433 crashing express server -
i not able capture node.js tedious error connectionerror: failed connect sqlserverip:1433
making express server crash unexpectedly. can please suggest me should avoid such crashes?
tedious@1.2.2 tedious-connection-pool@0.3.2 node --version v0.10.33
my tedious program here:
// mssql.js
// mssql.js "use strict"; // import modules var path = require('path'); var async = require('async'); var fs = require('fs'); var connectionpool = require('tedious-connection-pool'); var request = require('tedious').request; var types = require('tedious').types; // export module namespace var swmssqlc = exports; // constants var default_connlimit_max = 30; var default_connlimit_min = 0; var default_useutc = true; var default_requesttimeout = 15000; var default_conntimeout = 15000; /** * mssql class wrapper solarwinds * @param {object} connprop: contains following connection properties * @param {string} connprop.user: user of database account * @param {string} connprop.password: password database account * @param {string} connprop.database: database name * @param {string} connprop.instancename: instance name * @param {string} connprop.host: hostname of server * @return {object} object */ swmssqlc.swdbclient = function swdbclient(connprop) { this.user = connprop.user; this.password = connprop.password; this.database = connprop.database; this.instancename = connprop.instancename; this.connecttimeout = connprop.connecttimeout || default_conntimeout; this.requesttimeout = connprop.requesttimeout || default_requesttimeout; this.useutc = connprop.useutc || default_useutc; this.host = connprop.host; this.connectionlimitmax = connprop.connectionlimitmax || default_connlimit_max this.connectionlimitmin = connprop.connectionlimitmin || default_connlimit_min this.pool = null; this.connprop = { server : this.host, username : this.user, password : this.password, options : { database : this.database, instancename : this.instancename, connecttimeout : this.connecttimeout, requesttimeout : this.requesttimeout, useutc : this.useutc } }; this.poolconf = { min : this.connectionlimitmin, max : this.connectionlimitmax, }; }; swmssqlc.swdbclient.prototype.connect = function connect(callback) { var pool = new connectionpool(this.poolconf, this.connprop); this.pool = pool; // verify connection pool.acquire(function (err, connection) { console.log('connecting swmssqlc'); if (err) { console.error('error connecting swmssqlc server connprop:', this.connprop); return callback(err); } connection.on('error', function(err) { console.error('error connecting swmssqlc server due connection error'); return callback(err); }); connection.release(); return callback(null); }); pool.on('error', function(err) { console.error('error pool-connecting swmssqlc server connprop:', this.connprop); return callback(err); }); }; swmssqlc.swdbclient.prototype.disconnect = function disconnect(callback) { var pool = this.pool; console.log('disconnecting swmssqlc'); pool.drain(callback); }; swmssqlc.swdbclient.prototype.runqry = function runqry(qry, args, callback) { /** * run query * @param {string} qry: sql query * @param {object} args: object args.params = {'paramname': {paramvalue: 1, paramtype: tedious.types.type}} * @param {number} callback(err, port) function * @return callback return */ // console.log('running swmssqlc qry:', qry); // log (testing) this.pool.acquire(function(err, connection) { if (err) { console.error('swmssqlc-runqry-cannot acquire error:', err); return callback(err); } connection.on('error', function(err) { console.error('error executing query on swmssqlc server due connection error'); return callback(err); }); var rows = []; var request = new request(qry, function(err, rowcount) { if (err) { console.error('swmssqlc-runqry-request error:', err); connection.release(); return callback(err); } else { connection.release(); return callback(null, rows); } }); request.on('row', function(columns) { rows = columns }); if (args && args.params) { (var paramname in args.params) { request.addparameter(paramname.tostring(), args.params[paramname].paramtype, args.params[paramname].paramvalue); } } connection.execsql(request); }); };
// error here
swmssqlc-runqry-request error: { [requesterror: timeout: request failed complete in 15000ms] name: 'requesterror', message: 'timeout: request failed complete in 15000ms', code: 'etimeout' } swmssqlc-runqry-request error: { [requesterror: timeout: request failed complete in 15000ms] name: 'requesterror', message: 'timeout: request failed complete in 15000ms', code: 'etimeout' } connectionerror: failed connect sqlserverip:1433 in 15000ms @ connection.connecttimeout (/home/amit/workspace/myproject/node_modules/tedious/lib/connection.js:628:26) @ null._ontimeout (/home/amit/workspace/myproject/node_modules/tedious/lib/connection.js:3:59) @ timer.listontimeout [as ontimeout] (timers.js:112:15)
i have found problem code... because had throw
exception in callback error swmssqlc.connect()
being called when pool.on
raise exception.
Comments
Post a Comment