How to use the tedious.Connection function in tedious

To help you get started, we’ve selected a few tedious 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 microsoft / mssql-docker / oss-drivers / tedious / sample.js View on Github external
var Connection = require('tedious').Connection;
var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;

// Create connection to database
var config = {
  userName: '$DB_USERNAME', // update me
  password: '$DB_PASSWORD', // update me
  server: '$DB_HOST'
}
var connection = new Connection(config);

// Attempt to connect and execute queries if connection goes through
connection.on('connect', function(err) {
  if (err) {
    console.log(err);
  } else {
    console.log('Connected');
  }
});
github Azure / azure-sql-database-samples / node.js / windows / sample_nodejs_win.js View on Github external
var Connection = require('tedious').Connection;
var config = {
    userName: 'yourusername',
    password: 'yourpassword',
    server: 'yourserver.database.windows.net',
    // When you connect to Azure SQL Database, you need these next options.
    options: {encrypt: true, database: 'AdventureWorks'}
};
var connection = new Connection(config);
connection.on('connect', function(err) {
    // If no error, then good to proceed.
    console.log("Connected");
    executeStatement();
    //executeStatement1();

});

var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;

function executeStatement() {
    request = new Request("SELECT TOP 10 Title, FirstName, LastName from SalesLT.Customer;", function(err) {
    if (err) {
        console.log(err);} 
    });
github Azure / azure-sql-database-samples / node.js / linux / sample_nodejs_linux.js View on Github external
var Connection = require('tedious').Connection;
var config = {
    userName: 'yourusername',
    password: 'yourpassword',
    server: 'yourserver.database.windows.net',
    // When you connect to Azure SQL Database, you need these next options.
    options: {encrypt: true, database: 'AdventureWorks'}
};
var connection = new Connection(config);
connection.on('connect', function(err) {
    // If no error, then good to proceed.
    console.log("Connected");
    executeStatement();

});

var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;

function executeStatement() {
    request = new Request("SELECT TOP 10 Title, FirstName, LastName from SalesLT.Customer;", function(err) {
    if (err) {
        console.log(err);} 
    });
    var result = "";
github knex / knex / lib / dialects / mssql / index.js View on Github external
if (isNaN(cfg.options.requestTimeout))
          cfg.options.requestTimeout = 15000;
        if (cfg.options.requestTimeout === Infinity)
          cfg.options.requestTimeout = 0;
        if (cfg.options.requestTimeout < 0) cfg.options.requestTimeout = 0;

        if (this.config.debug) {
          cfg.options.debug = {
            packet: true,
            token: true,
            data: true,
            payload: true,
          };
        }

        const tedious = new tds.Connection(cfg);

        // prevent calling resolve again on end event
        let alreadyResolved = false;

        function safeResolve(err) {
          if (!alreadyResolved) {
            alreadyResolved = true;
            resolve(err);
          }
        }

        function safeReject(err) {
          if (!alreadyResolved) {
            alreadyResolved = true;
            reject(err);
          }
github Azure / meta-azure-service-broker / test / utils / azuresqldbClient.js View on Github external
function(callback) {
        log.debug('Connecting to SQL server %s%s and database %s', sqlserverName, serverSuffix, sqldbName);
        connection = new Connection(config);
        connection.on('connect', function(err) {
          var message = 'The SQL Database can %sbe connected.';
          nextStep(err, message, callback);
        });
      },
      function(callback) {
github erhangundogan / sql2mongodb / sql.js View on Github external
sqlConnection.prototype.tableCount = function(table, callback) {
  var self = this,
      conn = new Connection(self.config);

  conn.on("connect", function(err) {
    if (err) {
      console.log(err);
      callback(err, null);
    } else {
      var queryString = [];
      /*
       select SUM(rows) As Rows
       from sys.partitions p
       left join sys.objects o on o.object_id = p.object_id
       where (p.index_id in (0,1)) and (o.is_ms_shipped = 0) and (o.type_desc = 'USER_TABLE') and (o.name = 'table')
       */
      queryString.push("SELECT SUM(rows) AS Rows");
      queryString.push("FROM sys.partitions p");
      queryString.push("LEFT JOIN sys.objects o ON o.object_id = p.object_id");
github DFEAGILEDEVOPS / MTC / spike-worker / bulkImport.js View on Github external
return new Promise((resolve, reject) => {
    connection = new Connection(dbConfig)
    connection.on('connect', async function (error) {
      if (error) {
        reject(error)
      }
      await doBulkInsert(csvPayload, schoolLookupDisabled, schoolData)
      resolve()
    })
  })
}
github sematext / logagent-js / lib / plugins / input / mssql.js View on Github external
function InputMSSql (config, eventEmitter) {
  this.config = config
  this.eventEmitter = eventEmitter
  this.started = false
  this.connection = new Connection(config.connectioninfo)
  if (this.config.interval < 1) {
    this.config.interval = 1
  }
}
github tinkerscript / sqlssb / source / dataAdapter.js View on Github external
_connect () {
    const { server, user, password, database, encrypt = false } = this._config

    const connection = new Connection({
      server,
      userName: user,
      password,
      options: {
        encrypt,
        database,
        ...driverSettings
      }
    })

    return new Promise((resolve, reject) => {
      connection.on('connect', err => {
        if (err) {
          reject(err)
          return
        }