Node-mssql: Transaction 'acquire' undefined

Created on 8 Jun 2015  路  2Comments  路  Source: tediousjs/node-mssql

Hi, I got an error when I try to use transaction.

var connection = new sql.Connection(databaseConfig);
var transaction = new sql.Transaction(connection);
transaction.begin(function(err) {
  console.log('begin transaction');
});

Error: TypeError: Cannot read property 'acquire' of undefined
at Transaction.TediousTransaction.begin (..\node_modules\mssql\libtedious.js:447:36)
at Transaction._begin (..\node_modules\mssql\lib\main.js:838:58)
at Transaction.begin (..\node_modules\mssql\lib\main.js:816:21)

TediousTransaction.prototype.begin = function(callback) {
  this._aborted = false;
  this._rollbackRequested = false;
  return this.connection.pool.acquire((function(_this) {
    return function(err, connection) {
      if (err) {
        return callback(err);
      }
      _this._pooledConnection = connection;
      _this._pooledConnection.on('rollbackTransaction', _this._abort);
      return connection.beginTransaction(function(err) {
        if (err) {
          err = TransactionError(err);
        }
        return callback(err);
      }, _this.name, _this.isolationLevel);
    };
  })(this));
};

Problem is the acquire at connectionpool. Did I make a mistake?

If you need more informations let me know.

Most helpful comment

You're initializing transaction before the connection is established. Try this:

var connection = new sql.Connection(databaseConfig, function(err) {
    var transaction = new sql.Transaction(connection);
    transaction.begin(function(err) {
        console.log('begin transaction');
    });
});

All 2 comments

You're initializing transaction before the connection is established. Try this:

var connection = new sql.Connection(databaseConfig, function(err) {
    var transaction = new sql.Transaction(connection);
    transaction.begin(function(err) {
        console.log('begin transaction');
    });
});

it works! thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mhunting picture mhunting  路  6Comments

Halt001 picture Halt001  路  3Comments

brilvio picture brilvio  路  3Comments

rsmolkin picture rsmolkin  路  3Comments

PatrikFomin picture PatrikFomin  路  6Comments