Permalink
Browse files

Added code to ensure connection being closed by MigrationRunner

(VersionLoader.LoadVersionInfo() reopened it)
  • Loading branch information...
1 parent 36bcd49 commit c36650579e56807bb874f17f45bf44434ee90e7b @dabide committed Oct 24, 2012
View
22 src/FluentMigrator.Runner/MigrationRunner.cs
@@ -95,6 +95,10 @@ public void MigrateUp(bool useAutomaticTransactionManagement)
if (useAutomaticTransactionManagement) { Processor.RollbackTransaction(); }
throw;
}
+ finally
+ {
+ if (useAutomaticTransactionManagement) { Processor.CloseConnection(); }
+ }
}
public void MigrateUp(long targetVersion)
@@ -113,11 +117,15 @@ public void MigrateUp(long targetVersion, bool useAutomaticTransactionManagement
if (useAutomaticTransactionManagement) { Processor.CommitTransaction(); }
VersionLoader.LoadVersionInfo();
}
- catch (Exception ex)
+ catch (Exception)
{
if (useAutomaticTransactionManagement) { Processor.RollbackTransaction(); }
throw;
}
+ finally
+ {
+ if (useAutomaticTransactionManagement) { Processor.CloseConnection(); }
+ }
}
private IEnumerable<long> GetUpMigrationsToApply(long version)
@@ -158,6 +166,10 @@ public void MigrateDown(long targetVersion, bool useAutomaticTransactionManageme
if (useAutomaticTransactionManagement) { Processor.RollbackTransaction(); }
throw;
}
+ finally
+ {
+ if (useAutomaticTransactionManagement) { Processor.CloseConnection(); }
+ }
}
private IEnumerable<long> GetDownMigrationsToApply(long targetVersion)
@@ -237,6 +249,10 @@ public void Rollback(int steps, bool useAutomaticTransactionManagement)
if (useAutomaticTransactionManagement) { Processor.RollbackTransaction(); }
throw;
}
+ finally
+ {
+ if (useAutomaticTransactionManagement) { Processor.CloseConnection(); }
+ }
}
public void RollbackToVersion(long version)
@@ -271,6 +287,10 @@ public void RollbackToVersion(long version, bool useAutomaticTransactionManageme
if (useAutomaticTransactionManagement) { Processor.RollbackTransaction(); }
throw;
}
+ finally
+ {
+ if (useAutomaticTransactionManagement) { Processor.CloseConnection(); }
+ }
}
public Assembly MigrationAssembly
View
12 src/FluentMigrator.Runner/Processors/Firebird/FirebirdProcessor.cs
@@ -145,10 +145,7 @@ public override void CommitTransaction()
Announcer.Say("Committing Transaction");
Transaction.Commit();
WasCommitted = true;
- if (Connection.State != ConnectionState.Closed)
- {
- Connection.Close();
- }
+ CloseConnection();
ClearLocks();
}
@@ -177,11 +174,16 @@ public override void RollbackTransaction()
}
}
+ CloseConnection();
+ ClearLocks();
+ }
+
+ public override void CloseConnection()
+ {
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
}
- ClearLocks();
}
public virtual void CommitRetaining()
View
10 src/FluentMigrator.Runner/Processors/Jet/JetProcessor.cs
@@ -34,17 +34,19 @@ public override void CommitTransaction()
Announcer.Say("Committing Transaction");
Transaction.Commit();
WasCommitted = true;
- if (Connection.State != ConnectionState.Closed)
- {
- Connection.Close();
- }
+ CloseConnection();
}
public override void RollbackTransaction()
{
Announcer.Say("Rolling back transaction");
Transaction.Rollback();
WasCommitted = true;
+ CloseConnection();
+ }
+
+ public override void CloseConnection()
+ {
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
View
10 src/FluentMigrator.Runner/Processors/Postgres/PostgresProcessor.cs
@@ -100,17 +100,19 @@ public override void CommitTransaction()
Announcer.Say("Committing Transaction");
Transaction.Commit();
WasCommitted = true;
- if (Connection.State != ConnectionState.Closed)
- {
- Connection.Close();
- }
+ CloseConnection();
}
public override void RollbackTransaction()
{
Announcer.Say("Rolling back transaction");
Transaction.Rollback();
WasCommitted = true;
+ CloseConnection();
+ }
+
+ public override void CloseConnection()
+ {
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
View
4 src/FluentMigrator.Runner/Processors/ProcessorBase.cs
@@ -172,6 +172,10 @@ public virtual void RollbackTransaction()
{
}
+ public virtual void CloseConnection()
+ {
+ }
+
public abstract System.Data.DataSet ReadTableData(string schemaName, string tableName);
public abstract System.Data.DataSet Read(string template, params object[] args);
public abstract bool Exists(string template, params object[] args);
View
10 src/FluentMigrator.Runner/Processors/SqlServer/SqlServer2000Processor.cs
@@ -100,17 +100,19 @@ public override void CommitTransaction()
Announcer.Say("Committing Transaction");
Transaction.Commit();
WasCommitted = true;
- if (Connection.State != ConnectionState.Closed)
- {
- Connection.Close();
- }
+ CloseConnection();
}
public override void RollbackTransaction()
{
Announcer.Say("Rolling back transaction");
Transaction.Rollback();
WasCommitted = true;
+ CloseConnection();
+ }
+
+ public override void CloseConnection()
+ {
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
View
10 src/FluentMigrator.Runner/Processors/SqlServer/SqlServerCeProcessor.cs
@@ -120,10 +120,7 @@ public override void CommitTransaction()
transaction = null;
}
- if (connection.State != ConnectionState.Closed)
- {
- connection.Close();
- }
+ CloseConnection();
}
public override void RollbackTransaction()
@@ -138,6 +135,11 @@ public override void RollbackTransaction()
transaction.Rollback();
+ CloseConnection();
+ }
+
+ public override void CloseConnection()
+ {
if (connection.State != ConnectionState.Closed)
{
connection.Close();
View
10 src/FluentMigrator.Runner/Processors/SqlServer/SqlServerProcessor.cs
@@ -128,17 +128,19 @@ public override void CommitTransaction()
Announcer.Say("Committing Transaction");
Transaction.Commit();
WasCommitted = true;
- if (Connection.State != ConnectionState.Closed)
- {
- Connection.Close();
- }
+ CloseConnection();
}
public override void RollbackTransaction()
{
Announcer.Say("Rolling back transaction");
Transaction.Rollback();
WasCommitted = true;
+ CloseConnection();
+ }
+
+ public override void CloseConnection()
+ {
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
View
1 src/FluentMigrator/IMigrationProcessor.cs
@@ -34,6 +34,7 @@ public interface IMigrationProcessor : IQuerySchema
void BeginTransaction();
void CommitTransaction();
void RollbackTransaction();
+ void CloseConnection();
void Process(CreateSchemaExpression expression);
void Process(DeleteSchemaExpression expression);

0 comments on commit c366505

Please sign in to comment.