Addition to transaction fix

This commit is contained in:
s459315 2022-08-02 17:50:09 +02:00
parent db5e820841
commit 43f647d9b7

View File

@ -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()
{
if (!isClosed)
{
try
{
CommitTransaction();
}
catch
{
// TODO - log this issue
}
}
_transaction = null;
_connection = null;
}
}
}