cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

PowerApps Writing back to SQL?

I have an app which is up and running and writes back to Excel Online hosted on OneDrive. We do not find this a secure way as we have to give users of the Power App edit access to the Excel Online as well to successfully make the comment/write back.

 

We want to replace this with a On-Prem SQL Server Table. I am unsure of what rights are needed for the SQL Table besides reader and writer and how to go about replacing this Excel Online connection and how to go about making this happen. 

 

Any documentation/advice would be really helpful.

1 ACCEPTED SOLUTION

Accepted Solutions

My suggestion was a bit of a raw principle, but as I sat and thought there are a few ways you could do this i guess. So you could create a table that stores execution of SP'S. In your SP open with creating a record and flagging a Procedure started column. (Set the record ID as max(ID) +1 and store that value within the SP so it can be called at the end. Make sure you put this first part in a transaction and commit before executing the main part of the SP so that you definitely have a record of the proc starting even if it falls over later . At the end update the original record in a Procedure complete flag column. You theft have a full record of procedures failing to fully execute. Useful for debugging. You could even store all parameters passed to the proc in this execution table as this might also.help debugging.

As to how you get this info back to the PA user, it's never going to be as ideal as a Proc failed message immediately after execution of the flow, but it's a start.

View solution in original post

21 REPLIES 21

For what it's worth I recommend this approach based on my own experience. Not only is it more secure but infinitely more flexible. The app I've build pulls in Information from other DB servers which in turn pulls data from 3rd party software api's which means we can use Powerapps to bridge the gaps in off the shelf software and provide the bespoke elements without the need for costly supplier development.

If you intend to do this you will need to.set up a gateway on your network, but ideally as closet to, if not on the DB server (which no allows clustering of multiple gateways, to ensure good availability to your DB) to minimise latency. Our DBA set up the gateway, and although it took a little fiddling to get it working it was fairly straightforward.

One recommendation i would make is that rather than use the standard data links to your data source from within powerapps, that you play around with passing the edits through sql server stored procedures using Flow. This actually gives you a lot more flexibility, and security.
The gateway itself uses the specific SQL server user account details, however if you use stored procedures and pass the user name over as a parameter your stored procedure offers you no end of options for storing information related to the auditing of data.
You might find this takes a bit of time and someone who's comfortable at writing and adapting stored procedures, but I promise it's worth it as you engage the power of the DB rather than complicating your webapp front end.

Anyway, good luck to you in your endeavours.

thanks a lot for your reply John, I will surely try this out and discuss with my team.

+1 on John's suggestion to use Stored Procedures.

 

You can limit the SQL account to just executing the necessary procedures, no need to grant Insert/Update on the underlying tables.

 

The SP enforces data types and can have additional logic to validate the data.

 

Is easy to update if business rules change or underlying tables are restructured.  The SP may look the same to the PowerApp/Flow thats using it but it can be completly rewritten - meaning you don't have to rejigger those applications when things change in the database.

This is a great point. Once you've established your SP execution point you can effectively use it as a static API endpoint for posting data. At first I passed every piece of data as a separate parameter to the SP but each time I wanted to pass a new field I had to fiddle with the flow. Instead what I do now (generally) is pass all data fields across in a single string with my own syntax to delimit the data. I then have logic in the SP to split out the data into separate fields and update accordingly.
I still generally pass the username over as a separate parameter because generally any time someone edits the data I want to make an audit record so i'm always needing a username.

Like I say, this has taken some time to get to and you want to be comfortable with SQL, but having worked with lots of professional software suppliers who seem to give the front end too much of the data logic responsibilities, I'm a big fan of leveraging the massive capabilities of a DB like MSSQL in doing the heavy lifting, leaving your App to be nimble and user-friendly.
It gives you the advantage to develop the front and back ends on different release schedules.

So this is how my Power Apps looks like as of now which is connected to Excel Online and each of the sections in this screen like 'Type' , 'Date', 'Description' write back to the Excel Online. Additionally, I have considered the route of developing the stored procedure that has parameters capturing these details.

 

So my question is how do i define any kind of stored procedure within these 'data cards'/sections to write to the sp, is it just like changing the connection to SQL? I know I can connect to SQL but then it lists out Tables where I want these data cards to write back to, so I am kinda lost. 

 

Power Apps.PNG

I will offer here is my step-by-step guide for deploying the gateway and building your first app from SQL. Might help you get started and avoid some of the gotchas with licensing and such. 

Shane - Microsoft MVP, YouTube, and PowerApps Consulting for when you are in a bind to get this fixed quickly. And finally we now have PowerApps Training

So my own personal approach has been that instead of calling the main table to display (say firstly in a gallery and then the selected record in data cards) I use a database view (which poweapps now supports). Even if the view is just all unfiltered records and all columns from your table (i.e. identical to your core data table) to begin with. There main advantage here is the ability to control what information powerapps sees, but to do it from the database side. So for example...
If you ever want to soft delete a record you can add a simple bit column (isDeleted) into the table, but change the view so it filters out any of the deleted records (i.e. where isDeleted <> 1) and this way you never need to put that logic into your powerapps gallery filter.

Or if you want to join info from another table on, you can do this in the view without having to add and store additional field data in your core record.

So assuming you have your view set up and this is what's coming into.your gallery and being displayed in your sections, you just need to decide exactly how you go about the editing process for the users. But however you want to do this you need to make sure you create a SP in the database that accepts the parameters you want. So let's keep it conceptually simple, we create a SP that accepts parameters for each field you might potentially want to edit in an update. Let's say this is proc_tableUpdate. All parameters are set to NULL maybe which gives you the option of passing only changed values of the record. However if you want to pass over all values to the procedure that's not a problem it's just a case of whether you want to limit the data going across.

Your SP should just effectively be a UPDATE statement. It takes the values you pass it and updates the core record table (and does whatever else you want it to e.g. create an audit record of the change)

To access this SP from Powerapps you need to set up a flow from your powerapps home page, look for the Execute SQL Server stored procedure connector, and then if your gateway is up.and running correctly you should see your SP. the final set up for the flow will ask you to define the parameters but you click on "ask in powerapps" for each parameter space. You can assign a flow to an ON SELECT action in Powerapps, and you then give it the values from your powerapps items, such as drop downs, input boxes etc. The point is here that there are a million and one ways of designing this kind of interface then, and it just depends on your preferred way if setting it up. But ultimately the desired values go.into the flow as parameters and are therefore passed through the gateway to the SP as such.

So things I didn't touch on there are adding new records:
You can either do this using the same SP but use a MERGE function to distinguish between an update or an insert (or you can manually simulate this but SQL server's merge function is pretty valuable)
OR you can set up a separate SP (with an insert function) and flow to handle the insert of a new record of your PA process is different for updates and new records.

The other thing is that eventually you may just want to pass through a single string to your SP and come up with your own logical delimiting syntax to allow you to pull it apart the other side.

Hopefully this is a little help but suspect you'll still be searching around the forums for more info on things, because I've probably left a tonne of gaps in the process. The more I've delved into PA the more I've decoupled the Data handling from PA's own mechanisms and used flow to hand the data to the DB to process. As good as they are, I prefer the flexibility of SQL server in the long term, but this makes PA so much more straightforward and useful from a user front end builder.

Reading back my post I suspect I may have "over-contributed" a bit!

I really appreciate you taking the time out to post this and putting the effort needed to list it all out. This will be my weekend experiment for sure! Thanks again John for being really helpful and awesome with your detail driven posts.

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (2,590)