i'm using hangfire in asp.net mvc 5 project, uses ninject use same context in requestscope.
in hangfire dashboard, random errors like:
system.data.entity.core.entityexception: error occurred while starting transaction on provider connection. see inner exception details. ---> system.data.sqlclient.sqlexception: new transaction not allowed because there other threads running in session.
how can make entity, asp.net , hangfire work without getting transaction errors?
i bet errors can happen on other side (in web).
we encountered issues hangfire along side ninject. create separate kernel hangfire, bound in thread scope. this:
public class ninjecthangfire { public static ikernel createkernelforhangfire() { var kernel = new standardkernel(/*modules*/); try { kernel.bind<func<ikernel>>().tomethod(ctx => () => new bootstrapper().kernel).inthreadscope(); kernel.bind<ihttpmodule>().to<httpapplicationinitializationhttpmodule>().inthreadscope(); //other bindings } catch { kernel.dispose(); throw; } } }
and in startup:
globalconfiguration.configuration.useninjectactivator(ninjecthangfire.createkernelforhangfire());