There is already an open datareader associated with this connection which must be closed first

I deployed my Radzen app on a Windows Server under IIS. When I create a record for which I have custom code running in the OnCreated event I get the error message "There is already an open datareader associated with this connection which must be closed first" when I try to save the new record. Yet when I run the application from my development machine, either from within the Radzen IDE or the VS 2019 IDE, pointing to the exact same database, it all works well....

Any suggestion?

Thanks

Hi @semafox,

Try to register your DbContext as Transient:

services.AddDbContext<YoyrDbContext>(options =>
{
    options.UseSqlServer(Configuration.GetConnectionString("YourConnection"));
}, ServiceLifetime.Transient);

You need to add you Startup.cs to application ignore list.

I did the suggested change but it did not help.

        services.AddScoped<LlDataService>();

        services.AddDbContext<LenoxLaser.Data.LlDataContext>(options =>
        {
          options.UseSqlServer(Configuration.GetConnectionString("LLDataConnection"));
        }, ServiceLifetime.Transient);

Try to set MultipleActiveResultSets=true in your connection string:

1 Like

That fixed it, thanks!