Ticket Q438763
Visible to All Users

Running a stored procedure in a transaction

created 12 years ago

I need to execute a stored procedure after the deposit
of several objects. I need to
run a stored procedure in a transaction
with saving objects.scenario
<para>

  1. Create one master object and several detail object</para>

  2. Modify this objects
    in detail view <para>

  3. Save and close detail view</para>

Execute
 my store procedure with manipulate with
data from object (manipulate with large number another data in db – some grouping
etc.) – save object and execute tore procedure must be in transaction<para>

It is it posible do this? How?</para>
Štěpán L.

Answers

created 12 years ago (modified 12 years ago)

Hello Stepan,
I am afraid that explicit database transactions are not supported in XAF. You can only use XPO transactions. To do this, execute the stored procedure in the ObjectSpace.Committing event handler.

    Show previous comments (4)
    BA BA
    Bassam Abdelaal 9 years ago

      Thank you for your code ,

      1. i don't understand why you put e.Cancel=true at the beginning of the method , I read at documentation to put e.cancel=true when you want to cancel the event and prevent saving the data , but later you save it thru ObjectSpace.CommitChanges();
      2. why you check for if (!e.Cancel) at the beginning?
      3. your answer to my 2 questions are no but you provided a code sample , is this means it can work but you don't guarantee it in all scenario as you said or it can work with direct SQL and not with stored procedure call ? im a little confused would you pls explain
        Thank you
      BA BA
      Bassam Abdelaal 9 years ago
        1. you set e.cancel=true to prevent normal XAF saving and provide a custom saving , I figured this out , pls correct me if im wrong
          still the other 2 questions please
        Anatol (DevExpress) 9 years ago
          1. Yes, you are right.
          2. The e.Cancel property is checked for the case if some other controller already handles this event and cancels the saving operation.
          3. In my initial answer, I did not suggest using an explicit transaction, and, as far as I understand, Stepan's task could be implemented without it, i.e. just by calling a stored procedure before the default Save operation. You requested the capability to rollback all changes in a single transaction, so that solution could not be used in your case. That is why I suggested another solution with an explicit transaction. You can execute a stored procedure with this solution.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.