web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to handle concurre...
Power Apps
Unanswered

How to handle concurrency in a canvas app

(0) ShareShare
ReportReport
Posted on by 21
I am developing a canvas app that can edit data on a table in SQL server. How to handle concurrency if multiple users can use this app and prevent bad data.
 
 
Categories:
I have the same question (0)
  • Ravi-Prajapati Profile Picture
    416 Super User 2025 Season 2 on at

    1. Use Row Versioning (Optimistic Concurrency)

    SQL Server provides a row versioning mechanism using rowversion (or timestamp) columns.

    Steps to Implement:

    1. Add a rowversion column to your SQL table:

       
      sql
      ALTER TABLE YourTable ADD RowVersionColumn ROWVERSION;
      • This column auto-updates every time a row is modified.
    2. Retrieve the row version when loading data into your Canvas app:

      • When a user selects a record, store the rowversion value.
    3. Check row version before updating:

      • When submitting updates, compare the stored rowversion with the current rowversion in SQL.
      • If they match, allow the update.
      • If they don’t match, inform the user that the data has changed.
    4. Modify the SQL Update Query:

       
      sql
      UPDATE YourTable
      SET Column1 = @NewValue, Column2 = @NewValue2
      WHERE ID = @RecordID AND RowVersionColumn = @StoredRowVersion;
    5. Check affected rows:

      • If rows affected = 0, another user has already modified it.
      • Show a message to reload the latest data.

    🔹 2. Locking (Pessimistic Concurrency) - Alternative Approach

    If data integrity is highly critical, you can implement record locking:

    • Add a LockedBy column in your SQL table.
    • When a user starts editing, store their UserID in LockedBy.
    • Prevent other users from modifying until the first user saves or cancels.

    🔥 Downside: Can cause records to remain locked if a user forgets to save.


    🔹 3. Last Modified Timestamp (Soft Concurrency)

    • Instead of rowversion, store a LastModifiedDate column (datetime).
    • Compare timestamps before updating.
    • This is less strict than row versioning but still prevents overwrites.

    🔹 4. Prevent Overwrites with Patch in Power Apps

    If using Power Automate or SQL Patch, add an extra check before updating:

     
    PowerApps
    If(
    LastModified <> LookUp(SQLTable, ID = SelectedID).LastModified,
    Notify("Data has changed! Refresh and try again.", NotificationType.Error),
    Patch(SQLTable, Lookup(SQLTable, ID = SelectedID), {Column1: NewValue})
    )

    💡 Best Practice Recommendation

    • ✅ Use Row Versioning (rowversion) for reliable optimistic concurrency.
    • ✅ Use Locks (LockedBy) if you want pessimistic concurrency.
    • ✅ Use timestamps (LastModified) if you don’t need strict control.
  • Viji Profile Picture
    21 on at
    I have tried #1 suggested but row version is not supported by power apps so storing it in app and updating does not work.
    I am not aware of a way to make canvas app store the rowversion as it is so that I can use it to update.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard