protected void Command(User user, ServiceCommandAction action) { // If no action dont' bother with the connection or command if (action == null) { return; } // Get a connection var connection = user.GetConnection(); // and create a command instance try { using (DbCommand command = connection.CreateCommand()) { if (user.ConnectionProfile.Timeout.GetValueOrDefault(-1) > 0) { if (user.ConnectionProfile.Timeout != null) { command.CommandTimeout = user.ConnectionProfile.Timeout.Value; } } // invoke the action with the command action(connection, command); } } finally { if (!user.InTransaction) { connection.Dispose(); } } }
protected void Command(DbConnection conn, ServiceCommandAction action) { if (action == null) { return; } try { if (conn.State == System.Data.ConnectionState.Closed) { conn.Open(); } using (DbCommand cmd = conn.CreateCommand()) { action(conn, cmd); } } finally { } }