/// <summary> /// This is the core execution function, it accept a simple functor that will accept a sqlcommand /// the command is created in the core of the function so it really care of all the standard /// burden of creating connection, creating transaction and enlist command into a transaction. /// </summary> /// <param name="functionToExecute">The delegates that really executes the command.</param> /// <param name="connection"></param> public static void Execute(Action <DbCommand, DbProviderFactory> functionToExecute, ConnectionStringSettings connection) { DbProviderFactory factory = GetFactory(connection); using (ConnectionData connectionData = CreateConnection(connection)) { DbCommand command = null; try { using (command = factory.CreateCommand()) { command.CommandTimeout = 120; command.CommandType = CommandType.Text; connectionData.EnlistCommand(command); functionToExecute(command, factory); } connectionData.Commit(); } catch (Exception ex) { if (logger.IsErrorEnabled) { logger.Error("Could not execute Query:" + DumpCommand(command), ex); } connectionData.Rollback(); throw; } } }