1

I want to create a SQL connection and import data from an app (Shoutouts template) to SQL database. I created a SQL connection and tried to import the data in there but I got this error.

CreatedOnDateTime: The specified column is generated by the server and can't be specified

I do have the CreatedOnDateTime column created but I guess it's datatype is not the same or something else.

Where can I look and see what fields and datatypes are being imported from PowerApps to SQL table in PowerApps via SQL connection?

Thank you for your help!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Mixer
  • 11
  • 3
  • Can you provide more details about this error? Where do you get it? In the portal (web.powerapps.com), in the studio (create.powerapps.com), somewhere else? If in the studio, which controls and which formulas / expressions are you using? – carlosfigueira Aug 14 '18 at 21:47
  • This error occurred in the portal when I played the app and submitted a shoutout. Under the studio, I picked SQL connection (Azure) as datasource. – Mixer Aug 15 '18 at 17:04
  • Are you talking about the 'Shoutouts' template? By default, that sample / template uses an Excel-backed data source (OneDrive, DropBox, Google Drive, etc.). If this is the case, and you are using a SQL connection, it means that you updated the app in the Studio. What changes were made to the app, and how were the SQL tables created? That information is important for others to know what is going on with your app. – carlosfigueira Aug 16 '18 at 03:13
  • That is correct, it's the Shoutouts template and it was written to Excel file fine. But it could not write to SQL table. I created the table myself base on the data I got from Excel file. I assumed the datatypes are not aligned. I just updated the screens and nothing else. Is the log file somewhere that I can look into? – Mixer Aug 16 '18 at 21:17

1 Answers1

0

Overall, there's no easy way to find out the structure of a data source in PowerApps (please create a new feature request in the PowerApps Ideas board for that). There is a convoluted way to find it out, however, which I'll go over here.

But for your specific problem, this is the schema of a SQL table that would match the schema of the data source in PowerApps:

CREATE TABLE PowerAppsTest.StackOverflow51847975 (
    PrimaryID BIGINT PRIMARY KEY,
    [Id] NVARCHAR(MAX),
    [Message] NVARCHAR(MAX),
    CreatedOnDateTime NVARCHAR(MAX),
    CreatorEmail NVARCHAR(MAX),
    CreatorName NVARCHAR(MAX),
    RecipientEmail NVARCHAR(MAX),
    RecipientName NVARCHAR(MAX),
    ShoutoutType NVARCHAR(MAX),
    [Image] IMAGE
)

Now for the generic case. You've been warned that this is convoluted, so proceed at your own risk :)

First, save the app locally to your computer: Save to local computer

The app will be saved with the .msapp extension, but it's basically a .zip file. If you're using Windows, you can rename it to change the extension to .zip and you'll be able to uncompress and extract the files that describe the app.

One of those files, Entities.json, contains, among other things, the definition of the schema of all data sources used in the app. The file is a huge JSON file, and it has all of its whitespaces removed, so you may want to use some online tool to format (or prettify) the JSON to read it easier. Once this is done, you can open the file in your favorite text editor (anything better than Notepad should be able to handle it).

With the file opened, search for an entry in the JSON root with the property "Name" and the value equal to the name of the data source. For example, in the shoutouts app case, the data source is called "Shoutout", so search for

"Name": "Shoutout"

You'll have to remove the space if you didn't pretty-print the JSON file prior to opening it. This should be an object that describes the data source, and it has one property called DataEntityMetadataJson that has the data source schema, formatted as a JSON string. Again in the Shoutouts example, this is the value:

"{\"name\":\"Shoutout\",\"title\":\"Shoutout\",\"x-ms-permission\":\"read-write\",\"schema\":{\"type\":\"array\",\"items\":{...

Notice that it again is not pretty-printed. You'll first need to decode that string, then pretty-print it again, and you'll end up with something like this:

{
  "name": "Shoutout",
  "title": "Shoutout",
  "x-ms-permission": "read-write",
  "schema": {
    "type": "array",
    "items": {
      "type": "object",
      "properties": {
        "PrimaryID": {
          "type": "number",
          "format": "double",
          ...
        },
        "Message": {
          "type": "string",
          ...
        },
        "Image": {
          "type": "string",
          "format": "uri",
          "x-ms-media-kind": "image",
          ...
        },
        "Id": {
          "type": "string",
          ...
        },
        "CreatedOnDateTime": {
          "type": "string",
          ...
        },
    ...

And this is the schema for the data source. From that I recreated the schema in SQL, removed the reference to the Shoutout data source from the app (which caused many errors), then added a reference to my SQL table, and since it has a different name, went looking for all places that have errors in the app to fix those.

Hope this helps!

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171