diff --git a/RMDataManagerLibrary/Internal/DataAccess/SqlDataAccess.cs b/RMDataManagerLibrary/Internal/DataAccess/SqlDataAccess.cs index b5f6a10..a86ba6e 100644 --- a/RMDataManagerLibrary/Internal/DataAccess/SqlDataAccess.cs +++ b/RMDataManagerLibrary/Internal/DataAccess/SqlDataAccess.cs @@ -43,8 +43,10 @@ namespace RMDataManagerLibrary.Internal.DataAccess private IDbConnection _connection; private IDbTransaction _transaction; + private bool isClosed = false; public void StartTransaction(string connectionStringName) { + isClosed = false; string connectionString = GetConnectionString(connectionStringName); _connection = new SqlConnection(connectionString); @@ -74,17 +76,32 @@ namespace RMDataManagerLibrary.Internal.DataAccess { _transaction?.Commit(); _connection?.Close(); + isClosed = true; } public void RollBackTransaction() { _transaction?.Rollback(); _connection?.Close(); + isClosed = true; } public void Dispose() { - CommitTransaction(); + if (!isClosed) + { + try + { + CommitTransaction(); + } + catch + { + // TODO - log this issue + } + } + + _transaction = null; + _connection = null; } } }