Transactions in the business layer

Topics: Data Access Application Block, General discussion
Jan 26, 2008 at 3:27 AM
Edited Jan 26, 2008 at 9:44 PM
I had a lot of persistance methods through several classes in a persistance namespace, things like this (my, Database db = DatabaseFactory.CreateDatabase("DB");, is placed as attribute):

public Int32 Delete(Int32 ID)
DbCommand dbCommand = db.GetStoredProcCommand("spfordelete");
db.AddInParameter(dbCommand, "@ID", DbType.Int32, ID);

return db.ExecuteNonQuery(dbCommand);

catch (Exception ex)
bool rethrow = ExceptionPolicy.HandleException(ex, "Policy");
if (rethrow)
return 0;

I need to call in a single transaction differents methods from different classes in the bussines layer, what should I do? I'm gonna use NT5 and SQL Server 2K

Jan 28, 2008 at 4:44 PM

I'm not sure what you mean by having the code to create your database places as attribute (is it that you have custom attributes to specify databases?). In any case, you may want to take a look at the transaction scopes (see topic "Using the TransactionScope Class" in the help file) for dealing with ambient transactions.