In this case you can't use the Transactions in the BLL Methods,
Instead you need to use the transaction inside the StoredProcedure , in this case your stored procedured may do more than one operation ,
and you can call that stored procedures in the same you do for any stored procedure...
Another approach is to use the Transactions in the DLL methods, this is an example :
SqlConnection sqlConnection = newSqlConnection();
sqlConnection.ConnectionString =
ConfigurationSettings.AppSettings["CString"].ToString();
SqlCommand sqlCommand = new SqlCommand();
SqlTransaction sqlTransaction = null;
try
{
sqlConnection.Open();
sqlTransaction =sqlConnection.BeginTransaction();
sqlCommand.Transaction = sqlTransaction;
sqlCommand.CommandText = "Insert intocustomervalues(8,'Joydip')";
sqlCommand.Connection = sqlConnection;
sqlCommand.ExecuteNonQuery();
sqlCommand.CommandText = "Insert intoproduct
values(1287,'Colgate')";
sqlCommand.Connection = sqlConnection;
sqlCommand.ExecuteNonQuery();
sqlTransaction.Commit();
}
catch (Exception e)
{
sqlTransaction.Rollback();
}
finally
{
sqlConnection.Close();
}
Note that for this approch , we don't handle the trasnaction in the Stored procedure , instead it will handled in the DAL Method .
Hope it helps