sql-serverpowerapps

"specified record was not found" error in Power Apps despite matching primary key


I am trying to update a record in a table in SQL Server using the Power Apps patch function. I added the connection to SQL Server and the patch function in PA.

Patch(
    myTable,
    LookUp(myTable, itemKey = myItemKey),
    {
    otherField: TextInput.Text
    }
);

At first I got an error that my SQL Server table needs a primary key in order to patch it. itemKey was not a primary key in my SQL Server table, so I made it the primary key.

Then I got the error:

Network error when using Patch function:specified record was not found

I double checked that the field in my patch function had the same name as the SQL Server column and that the strings were an exact match. Still the error persisted.

I found the solution which is related to a general problem with Power Apps that might lead also to other error messages. I am posting it here for the next person that is wasting their work time on debugging Power Apps


Solution

  • Power Apps does not refresh the metadata of your SQL tables even when you close and reload the app. You have to remove the connection to the SQL table and re-add it in order for Power Apps to become aware of the change.

    When you re-add the connection, power apps will find the primary key and the patching will be successful.

    This seems to be true in general when dealing with SQL connections in Power Apps. Be aware that whenever you are making changes to your SQL tables, you have to re-add the connection in power apps in order for it to become aware of the changes.