CSLA transactions not working for static methods (non DataPortal_xyz methods)

CSLA transactions not working for static methods (non DataPortal_xyz methods)

Old forum URL: forums.lhotka.net/forums/t/9734.aspx


krishna_navuduri posted on Tuesday, November 09, 2010

Hi,

I am using CSLA in my current project and running into some issues with transactions, I have a static method with in CSLA object in this method

I am calling different stored procedures, when exception happens my transactions are not working, could you please check below code and let me know

What I am doing wrong. Thanks

 

 

[Transactional(TransactionalTypes.TransactionScope)]

public static bool PurgeFinalization_CSLA(int personnelJobOrderID)

{

            bool bRetVal = true;

 

            try

            {

                using (var cn = ConnectionManager<SqlConnection>.GetManager(SqlDatabase.ScoutConnection, false))

                {

                    using (SqlCommand cm = cn.Connection.CreateCommand())

                    {

                        //purge finalization record//////////////////////////

                        cm.Parameters.Clear();

                        cm.CommandType = System.Data.CommandType.StoredProcedure;

                        cm.CommandType = CommandType.StoredProcedure;

                        cm.CommandText = "sp_JO_JobOrders_Personnel_Finalizations_Clean";

                        cm.Parameters.Add(SqlDatabase.ParameterFactory("jobOrder_Personnel_ID", personnelJobOrderID, DbType.Int32));

                        cm.ExecuteNonQuery();

 

 

                        //calling twice to check commit/rollback

                        cm.Parameters.Clear();

                        cm.CommandType = System.Data.CommandType.StoredProcedure;

                        cm.CommandType = CommandType.StoredProcedure;

                        cm.CommandText = "sp_JO_JobOrders_Personnel_Finalizations_Clean_not_exists";

                        cm.Parameters.Add(SqlDatabase.ParameterFactory("jobOrder_Personnel_ID", personnelJobOrderID, DbType.Int32));

                        cm.ExecuteNonQuery();

                    }

                }

            }

            catch (Exception ex)

            {

                bRetVal = false;

                throw;

            }

            return bRetVal;

 }

 

RockfordLhotka replied on Tuesday, November 09, 2010

The Transactional attribute can be applied to

In short, this attribute is used by the data portal to set up an appropriate transactional context before the data portal invokes your method. If your method isn't invoked by the data portal, the attribute has no meaning.

Your method is not something the data portal will invoke, so the attribute has no meaning.

Copyright (c) Marimer LLC