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.
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!
Most helpful comment
You're initializing transaction before the connection is established. Try this: