Skip to content

Commit

Permalink
Finally, fixing the connection pool deconstruction issue that has pla…
Browse files Browse the repository at this point in the history
…gued RH for a minute since switching to more than one connection!
  • Loading branch information
ferventcoder committed Oct 24, 2011
1 parent 663f6c2 commit cf9ebbd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
4 changes: 3 additions & 1 deletion product/roundhouse.databases.sqlserver/SqlServerDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public override void initialize_connections(ConfigurationPropertyHolder configur
}
configuration_property_holder.ConnectionStringAdmin = admin_connection_string;
//set_repository(configuration_property_holder);

//Pooling=false;
}

public override void set_provider()
Expand All @@ -78,7 +80,7 @@ public override void set_provider()

private static string build_connection_string(string server_name, string database_name, string connection_options)
{
return string.Format("Server={0};initial catalog={1};{2}", server_name, database_name, connection_options);
return string.Format("data source={0};initial catalog={1};{2}", server_name, database_name, connection_options);
}

public override void run_database_specific_tasks()
Expand Down
13 changes: 12 additions & 1 deletion product/roundhouse/connections/AdoNetConnection.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Data;

namespace roundhouse.connections
{
{
using System.Data.SqlClient;

public class AdoNetConnection : IConnection<IDbConnection>
{
private readonly IDbConnection server_connection;
Expand All @@ -16,6 +18,15 @@ public void open()
server_connection.Open();
}

public void clear_pool()
{
var sql_conn = server_connection as SqlConnection;
if (sql_conn != null)
{
SqlConnection.ClearPool(sql_conn);
}
}

public void close()
{
if (server_connection !=null && server_connection.State != ConnectionState.Closed)
Expand Down
5 changes: 3 additions & 2 deletions product/roundhouse/connections/IConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ namespace roundhouse.connections
{
public interface IConnection<T> : IDisposable
{
void open();
void close();
void open();
void clear_pool();
void close();
T underlying_type();
}
}
32 changes: 21 additions & 11 deletions product/roundhouse/databases/AdoNetDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,29 @@ public override void open_admin_connection()
public override void close_admin_connection()
{
Log.bound_to(this).log_a_debug_event_containing("Closing admin connection");
admin_connection.close();
if (admin_connection != null)
{
admin_connection.clear_pool();
admin_connection.close();
admin_connection.Dispose();
}

}

public override void open_connection(bool with_transaction)
{
Log.bound_to(this).log_a_debug_event_containing("Opening connection to '{0}'", connection_string);
server_connection = GetAdoNetConnection(connection_string);
server_connection.open();

set_repository();

if (with_transaction)
{
transaction = server_connection.underlying_type().BeginTransaction();
repository.start(true);
}

set_repository();
if (repository != null)
{
repository.start(with_transaction);
}
}

Expand All @@ -70,12 +78,14 @@ public override void close_connection()
}
if (repository != null)
{
repository.finish();
repository.finish();
}

if (server_connection != null)
{
server_connection.close();
server_connection.clear_pool();
server_connection.close();
server_connection.Dispose();
}
}

Expand Down Expand Up @@ -110,14 +120,14 @@ protected override void run_sql(string sql_to_run, ConnectionType connection_typ
}
catch (Exception ex)
{
Log.bound_to(this).log_a_debug_event_containing("Failure executing command, trying again. {0}{1}",Environment.NewLine,ex.ToString());
Log.bound_to(this).log_a_debug_event_containing("Failure executing command, trying again. {0}{1}", Environment.NewLine, ex.ToString());
run_command_with(sql_to_run, connection_type, parameters);
}
}

private void run_command_with(string sql_to_run,ConnectionType connection_type, IList<IParameter<IDbDataParameter>> parameters)
private void run_command_with(string sql_to_run, ConnectionType connection_type, IList<IParameter<IDbDataParameter>> parameters)
{
using (IDbCommand command = setup_database_command(sql_to_run, connection_type, parameters))
using (IDbCommand command = setup_database_command(sql_to_run, connection_type, parameters))
{
command.ExecuteNonQuery();
command.Dispose();
Expand Down

0 comments on commit cf9ebbd

Please sign in to comment.