public static async Task <ILoggedConnection <SqlConnection> > OpenConnection(this SqlServerCfg cfg, ILogger log) { var policy = Policy.Handle <SqlException>(e => e.Number == 40143).RetryBackoff("connecting to sql server", 3, log); var conn = cfg.Connection(); await policy.ExecuteAsync(() => conn.OpenAsync()); return(conn.AsLogged(log)); }
public static string ConnectionStirng(this SqlServerCfg cfg) => $"Server={cfg.Host};Initial Catalog={cfg.Db};Persist Security Info=False;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=10;Pooling=true;Min Pool Size={cfg.MinPoolSize}";
public static SqlConnection Connection(this SqlServerCfg cfg) => new SqlConnection(cfg.ConnectionStirng(), new SqlCredential(cfg.Creds.Name, cfg.Creds.SecureString()));