efcore: EF Core exception when i send multiple requests
I updated my project to ASP.NET Core 2.1 RTM. When I send multiple requests, i get this exception:
Exception has occurred: CLR/System.Data.SqlClient.SqlException
An exception of type 'System.Data.SqlClient.SqlException' occurred in Microsoft.EntityFrameworkCore.dll but was not handled in user code: 'Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.'
Inner exceptions found, see $exception in variables window for more details.
Innermost exception System.ComponentModel.Win32Exception : Unknown error 258
In MyContext
class:
public class MyContext : DbContext, IUnitOfWork
{
public MyContext(DbContextOptions<MyContext> options)
: base(options) { }
public virtual DbSet<MyEntity> MyEntity { get; set; }
}
In TestService
class:
public class TestService : ITestService
{
private readonly IUnitOfWork _uow;
private readonly DbSet<MyEntity> _myEntity;
public LogRecentService(IUnitOfWork uow)
{
_uow = uow;
_myEntity = _uow.Set<MyEntity>();
}
public void Add(MyEntity model)
{
_myEntity.Add(model);
_uow.SaveChanges();
}
}
In Startup
class:
services.AddScoped<IUnitOfWork, MyContext>();
services.AddEntityFrameworkSqlServer();
services.AddDbContextPool<MyContext>(options =>
{
string connectionString = Configuration.GetConnectionString("MyConnection");
options.UseSqlServer(
connectionString
, serverDbContextOptionsBuilder =>
{
var minutes = (int)TimeSpan.FromMinutes(3).TotalSeconds;
serverDbContextOptionsBuilder.CommandTimeout(minutes);
serverDbContextOptionsBuilder.EnableRetryOnFailure();
});
});
services.AddScoped<ITestService, TestService>();
Further technical details
EF Core version: 2.1 Operating system: Ubuntu 18.04 LTS
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (11 by maintainers)
@shakeri Thanks for trying. I’ll look into this some more next week.