Getting the below error
Inner Exception: “Object reference not set to an instance of an object.”
Stack Trace:
at System.Transactions.Transaction.GetPromotedToken()
The error comes from the line
connection.EnlistTransaction(Transaction.Current);
in below code even if i set enlist=false in the connection string.
internal T UseTransaction<T>([InstantHandle] Func<DbConnection, DbTransaction, T> func, IsolationLevel? isolationLevel)
{
> using (var transaction = CreateTransaction(isolationLevel ?? _options.TransactionIsolationLevel))
> {
> var result = UseConnection(connection =>
> {
> connection.EnlistTransaction(Transaction.Current);
> return func(connection, null);
> });
> transaction.Complete();
> return result;
> }
> }
when we set enlist=true, then we get error at the line
connection.Open();
from the below code
internal DbConnection CreateAndOpenConnection()
{
if (_existingConnection != null)
{
return _existingConnection;
}
var connection = new SqlConnection(_connectionString);
connection.Open();
return connection;
}
both the methods are present under Hangfire.SqlServer.SqlServerStorage class
Same code works when connected to the local DB (SQL server 2014).
Landed on a discussion c# - WCF Transaction against Azure SQL DB - Stack Overflow
not sure if it is relevant for this issue.
Please help.
Thanks in advance.