How to use the Connection function from mssql

Find comprehensive JavaScript mssql.Connection code examples handpicked from public code repositorys.

205
206
207
208
209
210
211
212
213
214
  requestTimeout: 1000 * 60 * 60, // one hour
  options: {
    encrypt: connection.sqlserverEncrypt
  }
}
var mssqlConnection = new mssql.Connection(sqlconfig, function (err) {
  if (err) {
    callback(err, queryResult)
  } else {
    var rowCounter = 0
fork icon759
star icon0
watch icon7

+ 5 other calls in file

42
43
44
45
46
47
48
49
50
51
    options: {
        encrypt: true // Use this if you're on Windows Azure
    }
}

var connection = new sql.Connection(config, function(err) {
    // ... error checks
    
    // Query
        
fork icon463
star icon0
watch icon0

+ 29 other calls in file

126
127
128
129
130
131
132
133
134
135
  port: argv.port || 1433,
  database: argv.database || 'master',
  requestTimeout: (argv.timeout || 60) * 1000
}

var connection = new sql.Connection(config, function(error) {
  if (error)
    return callback(error);

  callback(null, connection);
fork icon7
star icon21
watch icon5

+ 9 other calls in file

386
387
388
389
390
391
392
393
394
  };
})();

let runWithConnection = (() => {
  var _ref39 = _asyncToGenerator(function* (conn, run) {
    const connection = yield new _mssql.Connection(conn.dbConfig).connect();

    return run(connection);
  });
fork icon68
star icon0
watch icon2

+ 3 other calls in file

107
108
109
110
111
112
113
114
115
116
var upsert = function (items) {
  if (!items || items.length === 0) {
    return
  }

  var connection = new sql.Connection(config, function (err) {
    if (err) {
      console.log('ERROR:', err)
      throw err
    }
fork icon7
star icon4
watch icon2

59
60
61
62
63
64
65
66
67
68
var config

async.series([

  function defineConnection (cb) {
    connection = new sql.Connection(localConfig = {
      server: opts.mssql_server,
      port: +opts.mssql_port,
      user: opts.mssql_user,
      password: opts.mssql_password,
fork icon9
star icon0
watch icon53

+ 33 other calls in file

127
128
129
130
131
132
133
134
135
136
app.get('/', function (req, res) {
  res.sendFile(path.join(process.cwd(), '..', 'index.html'));
});

app.get('/api/matchups', function (req, res){
  let conSQL = new sql.Connection(dbConfig);
  let reqSQL = new sql.Request(conSQL);
  conSQL.connect(function(err) {
    if (err) {
      console.log(err);
fork icon0
star icon4
watch icon7

+ 3 other calls in file

116
117
118
119
120
121
122
123
124
125
    adapter.log.error(error.message);
}
var connectionPromise = q.defer();
function getConnection() {
    if (!sqlConnection) {
        sqlConnection = new sql.Connection(dbConfig, function (error) {
            if (error) {
                traceError(error);
                sqlConnection = null;
                connectionPromise = q.defer();
fork icon0
star icon3
watch icon3

183
184
185
186
187
188
189
190
191
192
} else if (!persistent && !connected) {
  if (!assigned) {
    connection.mssqlConnection = [];
  }

  connection.mssqlConnection[uniqId] = new mssql.Connection(marshalConfig(connection.config), function (err) {
    cb(err, uniqId);
  });
  registerErrorHandler(connection.mssqlConnection[uniqId]);
} else {
fork icon87
star icon3
watch icon3

+ 3 other calls in file

80
81
82
83
84
85
86
87
88
89
    lang: params.lang || 'DEFAULT',
  }
}

this.sqlConn = new Promise(function(resolve, reject) {
  var conn = new sql.Connection(config.db, function(err) {
    if (err) {
      return reject(err)
    }
    return resolve(conn)
fork icon1
star icon1
watch icon2

+ 5 other calls in file

19
20
21
22
23
24
25
26
27
28
    return config;
}

function connectToDb(_config, cb) {
    config = _config;
    connection = new sql.Connection(config, function (err) {
        if (!err) {
            logger.info(
                'connected to [' + config.database + '] database on [' + config.server + ']'
            );
fork icon3
star icon1
watch icon13

+ 5 other calls in file

8
9
10
11
12
13
14
15
16
17
var fs = require('fs');

var utils = require('./../../utils/utils');
var config = require('./../../config/config');

var Connection = mssql.Connection;

// Connection to db
var __connection = {
  context: new Connection(config.db),
fork icon1
star icon0
watch icon4

80
81
82
83
84
85
86
87
88
89
}

__connection() {
    const self = this;
    return new Promise((success, fail) => {
        new sql.Connection(self.config)
            .connect()
            .then((connection) => {
                self.connection = connection;
                self.connection.on('error', (err) => {
fork icon0
star icon0
watch icon2

+ 3 other calls in file

6
7
8
9
10
11
12
13
14
15
"SELECT ProcessName, LastID, LastActivityDate, @MAXID - LastID AS Delta " +
"FROM [dbo].[ProcessHistory] (nolock) " +
"WHERE ProcessName LIKE 'Engine%' ";

this.getRecentHistoryDelta = function getRecentHistoryDelta (onErr, onSucc) {
    cnn = new sql.Connection(config, function (err) {
                    if (err)
                            return onErr(err);

                    cnn.request().query(internalDetalQuery, function (err, rows) {
fork icon0
star icon0
watch icon2

17
18
19
20
21
22
23
24
25
26
        DECIMAL: sql.Decimal(18, 5),
        STRING: sql.VarChar(8000),
        DATE: sql.DateTime,
        BIT: sql.bit
    }
    this.connection = new sql.Connection(connectionString);
};

//método genérico para acciones get
DataAccess.prototype.query = function(stored, params, callback) {
fork icon0
star icon0
watch icon5

29
30
31
32
33
34
35
36
37
38
  'PostDistrikt',
  'Latitude',
  'Longitude'
];

this.connection = new sql.Connection({
  user: this.config.user,
  password: this.config.password,
  server: this.config.server,
  database: this.config.database
fork icon0
star icon0
watch icon5

128
129
130
131
132
133
134
135
136
137
if ( linksCount < maxLinks ) {

    var link = {
        ts: Date.now(),
        id: linkId,
        connection: new mssql.Connection(marshalConfig(connections[connection].config))
    };
    link.connection.connect(function (err) {
        return cb(err, link);
    });
fork icon0
star icon0
watch icon1