1
votes

I'm having a moment I'm sure but I can't work out where the problem stems from.

I've created a new Azure Mobile Service and am trying to insert one piece of data into a table called Product.

Product item = new Product();
    item.Name = "Test";
    Toast.makeText(MainMenu.this, "" + item.Name, toast.LENGTH_SHORT).show();
    mClient.getTable(Product.class).insert(item, new TableOperationCallback<Product>() {
        public void onCompleted(Product entity, Exception exception, ServiceFilterResponse response) {
            if (exception == null) {
                Toast.makeText(MainMenu.this, "Success!", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(MainMenu.this, "" + exception + "", Toast.LENGTH_SHORT).show();
            }
        }
    });

Now I'm setting the item = "TEST" as a string?

public class Product {
    public String ID;
    public String Name;
}

So my Class for the Mobile Service table is set to accept a string and the Database is asking for

USE [SQLDB] 

GO

/****** Object:  Table [dbo].[Product]    Script Date: 21/08/2016 11:12:18    ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Product](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [Name] [varchar](100) NULL,
    [thetimestamp] [datetime] NULL DEFAULT (getdate()),
    [deleted] [bit] NULL DEFAULT ((0)),
    [createdAt] [datetimeoffset](7) NOT NULL DEFAULT (CONVERT([datetimeoffset](7),sysutcdatetime(),(0))),
    [updatedAt] [datetimeoffset](7) NOT NULL DEFAULT (CONVERT([datetimeoffset](7),sysutcdatetime(),(0))),
PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
)

GO

SET ANSI_PADDING OFF
GO

Now I'm complete confused as to why my app gives me the following error:

com.microsoft.windowsazure.mobileservices.MobileServiceException: {"error":"Invalid data type provided"}

EDIT:

I'm still having this problem despite recreating all of the tables through the Azure Portal with all of the generated columns, I've also tried both VARCHAR (Auto Generated by Azure) and INT Primary Keys.

1
Are you using Azure Mobile Services in the classic Azure portal, or the new Azure Mobile Apps? The old one is deprecated. - lindydonna
Hiya, I'm using it in the new portal. This was a new project which is started 3 days ago and I set it up from scratch. I may potentially have some dated code in there where I've pulled it from previous projects though? - Josh Reynolds
There are a couple of possible causes - The create script is missing the version [timestamp] column - If you are using an integer primary key, you must specify this in the table configuration - The thetimestamp column should be a datetimeoffset(7) type - Was this table created by the mobile apps backend? It may be missing required defaults and triggers - Dale Anderson
Hi Dale, I've specified the Integer primary key as the Identifier and it auto increments and I've used this in the past when setting up a Mobile Service on the old style portal. The timestamp column is now present as I've added that in case it could be the problem but it hasn't fixed it. I can change the type of the columns but they have now been generated by the Azure Portal as I recreated the table there to ensure they're all there. Still having no luck though :( - Josh Reynolds

1 Answers

0
votes

try to change the data type "id" on your table:

[Id] [varchar]

because in your class "Product" you are defining as String