How to use the mssql.Connection 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 misterGF / sails-mssqlserver / test / integration / runner.js View on Github external
util.inspect(e)
  );
}

log.info('Testing `' + package.name + '`, a Sails/Waterline adapter.');
log.info('Running `waterline-adapter-tests` against ' + interfaces.length + ' interfaces...');
log.info('( ' + interfaces.join(', ') + ' )');
console.log();
log('Latest draft of Waterline adapter interface spec:');
log('http://links.sailsjs.org/docs/plugins/adapters/interfaces');
console.log();

var mssql = require('mssql');

console.log('Dropping any existing tables...');
var connection = new mssql.Connection({
  user: process.env.MSSQL_USER,
  password: process.env.MSSQL_PASSWORD,
  server: process.env.MSSQL_HOST,
  database: process.env.MSSQL_DATABASE,
}, function (err) {
  if(err && err.name.indexOf('ConnectionError') == 0) {
    console.log('Connection to DB not implemented yet.', err)
    return
  } else if(err) {
    throw err
  }

  new mssql.Request(connection).query([
    'while(exists(select 1 from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE=\'FOREIGN KEY\'))',
    'begin',
    'declare @sql nvarchar(2000)',
github LeanKit-Labs / seriate / src / connections.js View on Github external
function connect( name, config ) {
	var pool = getPool( name );
	if ( pool ) {
		log.warn( "Connection for \"%s\" that already exists - existing connection pool will be used.", name );
		return state.connections[ name ];
	}
	log.info( "Connecting to \"%s\" ( %s:%d - %s as %s )",
		name,
		config.host || config.server,
		config.port || 1433,
		config.database,
		config.user );
	pool = state.pools[ name ] = new sql.Connection( config );

	pool.on( "connect", function() {
		api.emit( "connected", { name: name } );
		log.info( "Connected to \"%s\"", name );
	} );

	pool.on( "close", function() {
		api.emit( "closed", { name: name } );
		log.info( "Closed connection to \"%s\"", name );
		pool.removeAllListeners();
		delete state.connections[ name ];
		delete state.pools[ name ];
	} );

	function onConnectionError( err ) {
		api.emit( "failed", { name: name, error: err } );
github totaljs / eshop / node_modules / sqlagent / sqlserver.js View on Github external
self.options.database = options.pathname.substring(1);
			if (options.port)
				self.options.port = options.port;
			var auth = options.auth;
			if (auth) {
				auth = auth.split(':');
				self.options.user = auth[0];
				self.options.password = auth[1];
			}
			pools_cache[self.$conn] = self.options;
		} else
			pools_cache[self.$conn] = self.options;
	} else
		self.options = pools_cache[self.$conn];

	self.db = new database.Connection(self.options, function(err) {
		if (err) {
			callback.call(self, err, null);
			return;
		}
		self._prepare(callback);
	});

	return self;
};
github misterGF / sails-mssqlserver / lib / adapter.js View on Github external
connectConnection: function (conn, cb) {
      var uniqId = _.uniqueId()
      var connection = connections[conn]
      var persistent = !!connection.config.persistent
      var assigned = !!connection.mssqlConnection
      var connected

      if (persistent) {
        connected = assigned && !!connection.mssqlConnection.connected
      } else {
        connected = assigned && connection.mssqlConnection[uniqId] && connection.mssqlConnection[uniqId].connected
      }

      if (persistent && !connected) {
        connection.mssqlConnection = new mssql.Connection(marshalConfig(connection.config), cb)
      } else if (!persistent && !connected) {
        if (!assigned) {
          connection.mssqlConnection = []
        }

        connection.mssqlConnection[uniqId] = new mssql.Connection(marshalConfig(connection.config), function (err) {
          cb(err, uniqId)
        })
      } else {
        _.defer(cb)
      }
    },
github sqlectron / sqlectron-core / src / db / clients / sqlserver.js View on Github external
export async function disconnect(conn) {
  const connection = await new Connection(conn.dbConfig);
  connection.close();
}
github sqlectron / sqlectron-core / src / db / clients / sqlserver.js View on Github external
async function runWithConnection(conn, run) {
  const connection = await new Connection(conn.dbConfig).connect();

  return run(connection);
}