public override void Dispose() { switch (Enum.Parse <MixEnums.DatabaseProvider>(MixService.GetConfig <string>("DatabaseProvider"))) { case 0: { SqlConnection.ClearPool((SqlConnection)RelationalDatabaseFacadeExtensions.GetDbConnection(this.get_Database())); break; } case 1: { MySqlConnection.ClearPool((MySqlConnection)RelationalDatabaseFacadeExtensions.GetDbConnection(this.get_Database())); break; } case 2: { NpgsqlConnection.ClearPool((NpgsqlConnection)RelationalDatabaseFacadeExtensions.GetDbConnection(this.get_Database())); break; } } this.Dispose(); return; }
public InventoryIntegrationEventService(IEventBus eventBus, InventoryContext inventoryContext, Func <DbConnection, IIntegrationEventLogService> integrationEventLogServiceFactory) { _inventoryContext = inventoryContext ?? throw new ArgumentNullException(nameof(inventoryContext)); _integrationEventLogServiceFactory = integrationEventLogServiceFactory ?? throw new ArgumentNullException(nameof(integrationEventLogServiceFactory)); _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus)); _eventLogService = _integrationEventLogServiceFactory(RelationalDatabaseFacadeExtensions.GetDbConnection(_inventoryContext.Database)); }
private List <string> GetListFromStoredProcedure(string spName, [CallerMemberName] string memberName = "", params ValueTuple <string, object>[] args) { try { if (spName != GetFoundDefectsProc && spName != InsertQ4LProc && spName != GetFoundDefectsBySerialProc && spName != GetFoundDefectsBySerialAndFovProc) { throw new SecurityException(); } var jsonList = new List <string>(); using (var connection = (SqlConnection)RelationalDatabaseFacadeExtensions.GetDbConnection(this.Database)) { using (var command = connection.CreateCommand()) { command.CommandType = CommandType.StoredProcedure; command.CommandText = spName; foreach (var arg in args) { command.Parameters.AddWithValue(arg.Item1, arg.Item2); } connection.Open(); var reader = command.ExecuteReader(); while (reader.Read()) { var row = ((IDataRecord)reader)[0].ToString(); if (!string.IsNullOrWhiteSpace(row)) { jsonList.Add(row); } } } } return(jsonList); } catch (SecurityException e) { Log.Error(e, "{0} in call to {1}: ", e.GetType().Name, memberName); throw; } catch (SqlException e) { Log.Error(e, "{0} in call to {1}: ", e.GetType().Name, memberName); throw; } catch (Exception e) { Log.Error(e, "{0} in call to {1}: ", e.GetType().Name, memberName); throw; } }
private void ExecuteStoredProcedure(string spName, [CallerMemberName] string memberName = "", params ValueTuple <string, object>[] args) { try { if (spName != GetFoundDefectsProc && spName != InsertQ4LProc && spName != GetFoundDefectsBySerialProc) { throw new SecurityException(); } using (var connection = (SqlConnection)RelationalDatabaseFacadeExtensions.GetDbConnection(this.Database)) { using (var command = connection.CreateCommand()) { command.CommandType = CommandType.StoredProcedure; command.CommandText = spName; foreach (var arg in args) { command.Parameters.AddWithValue(arg.Item1, arg.Item2); } connection.Open(); command.ExecuteNonQuery(); } } } catch (SecurityException e) { Log.Error(e, "{0} in call to {1}: ", e.GetType().Name, memberName); throw; } catch (SqlException e) { Log.Error(e, "{0} in call to {1}: ", e.GetType().Name, memberName); throw; } catch (Exception e) { Log.Error(e, "{0} in call to {1}: ", e.GetType().Name, memberName); throw; } }