Azure SQL: Adding a new job is failing

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


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


from the below code

internal DbConnection CreateAndOpenConnection()
            if (_existingConnection != null)
                return _existingConnection;

            var connection = new SqlConnection(_connectionString);

            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

not sure if it is relevant for this issue.

Please help.
Thanks in advance.

Found the issue. call to method to queue job was inside transaction which was somehow leading to Distribution Transaction and Azure SQL doesn’t support it.

Consider the code below:

        public override void UpdateFile(int intUniqueId)
            using (var scope = GetTransactionScope(...))
                 QueueJob<Updater>(x => x.Update(token, intUniqueId));

        private static void QueueJob<T>(Expression<Action<T>> action)

Removing the transaction scope in callee method works.