- 2026-07-27 V 1.0.0.3 Se habilita EnableRetryOnFailure en la conexion a la bd y se aumenta el timeout a 60 segundos
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.3" />
|
||||
<PackageReference Include="PropertyChanged.Fody" Version="4.1.0" />
|
||||
<PackageReference Include="tsEFCore8" Version="1.0.5" />
|
||||
<PackageReference Include="tsUtilidades" Version="1.1.18" />
|
||||
<PackageReference Include="tsUtilidades" Version="1.1.22" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -15,6 +15,7 @@ using static System.Net.Mime.MediaTypeNames;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using bdAsegasa.db;
|
||||
using bdAsegasa.dbcontext;
|
||||
using Pomelo.EntityFrameworkCore.MySql.Internal;
|
||||
|
||||
namespace bdAsegasa
|
||||
{
|
||||
@@ -56,33 +57,45 @@ namespace bdAsegasa
|
||||
});
|
||||
|
||||
private static string? ConexionPorDefecto=null;
|
||||
public static tscgestionasegasa NuevoContexto(string NombreConexion = "" ,bool Lazy = true, bool SoloLectura = false, bool ConEventoSavingChanges = false, string aplicaciones = "")
|
||||
public static tscgestionasegasa NuevoContexto(string NombreConexion = "", bool Lazy = true, bool SoloLectura = false, bool ConEventoSavingChanges = false, string aplicaciones = "")
|
||||
{
|
||||
string? cnx = null;
|
||||
if (NombreConexion=="")
|
||||
string cnx;
|
||||
if (string.IsNullOrEmpty(NombreConexion))
|
||||
{
|
||||
if (ConexionPorDefecto == null) ConexionPorDefecto = Conexion.ObtieneConexionDefecto();
|
||||
cnx = ConexionPorDefecto;
|
||||
cnx = ConexionPorDefecto;
|
||||
}
|
||||
else
|
||||
{
|
||||
cnx = Conexion.ObtieneConexionDefecto(NombreConexion);
|
||||
}
|
||||
|
||||
var ob = new DbContextOptionsBuilder<gestionasegasaContext>();
|
||||
// ob.UseLoggerFactory(_myLoggerFactory);
|
||||
// ob.UseInternalServiceProvider(<EnumeracionesService>)
|
||||
ob.UseMySql(cnx, Microsoft.EntityFrameworkCore.ServerVersion.Parse("5.7.0-mysql"));
|
||||
if (Lazy) ob.UseLazyLoadingProxies();
|
||||
if (SoloLectura) ob.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
var Opciones = ob.Options;
|
||||
tscgestionasegasa bd = new tscgestionasegasa(Opciones);
|
||||
|
||||
var optionsBuilder = new DbContextOptionsBuilder<gestionasegasaContext>();
|
||||
|
||||
// Ejemplo con Pomelo.EntityFrameworkCore.MySql
|
||||
optionsBuilder.UseMySql(cnx, ServerVersion.Parse("5.7.0-mysql"), mySqlOptions =>
|
||||
{
|
||||
// Habilita reintentos transitorios (por defecto 3 reintentos)
|
||||
mySqlOptions.EnableRetryOnFailure();
|
||||
|
||||
// Ajusta timeout de comando (segundos)
|
||||
mySqlOptions.CommandTimeout(60);
|
||||
|
||||
// Si quieres controlar número de reintentos y backoff:
|
||||
// mySqlOptions.EnableRetryOnFailure(maxRetryCount: 5, maxRetryDelay: TimeSpan.FromSeconds(5), errorNumbersToAdd: null);
|
||||
});
|
||||
|
||||
if (Lazy) optionsBuilder.UseLazyLoadingProxies();
|
||||
if (SoloLectura) optionsBuilder.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
|
||||
var opciones = optionsBuilder.Options;
|
||||
var bd = new tscgestionasegasa(opciones);
|
||||
bd.Aplicaciones = aplicaciones;
|
||||
if (ConEventoSavingChanges) bd.SavingChanges += GuardandoCambios;
|
||||
return bd;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//public static Datos.BBDD ObtieneBBDD(string NombreConexion)
|
||||
|
||||
private static void GuardandoCambios(object? sender, SavingChangesEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user