Dillon Drobena
Dillon Drobena

Reputation: 921

Azure mobile services exception in android, table does not exist

I'm trying to insert data into my Azure database, and I can connect just find but for some reason I am having issues inserting any data.

For reference here is my class description and how I'm initializing my MobileServiceClient

public class STUDENTS
{
    public String Id;
    public String email;
    public String password;
    public String FirstName;
    public String LastName;
    public String PhoneNumber;

    public STUDENTS(String email, String password, String fName, String lName, String pNumber) {
        this.email = email;
        this.password = password;
        this.FirstName = fName;
        this.LastName = lName;
        this.PhoneNumber = pNumber;
    }
}

So I'm trying to insert into a table named STUDENTS, and I'm positive it exists, and I can even create an instance of the table. I read some previous solutions over the internet that said having the table declaration structured as

MobileServiceTable table = mClient.getTable("STUDENTS", STUDENTS.class); 

Instead of

MobileServiceTable table = mClient.getTable(STUDENTS.class);

Seemed to help a lot of people, but I've tried it both ways and it hasn't worked. And the issue only arises when I try to insert an instance of my STUDENTS class into the database, I have no issue with creating a MobileServiceTable from a known class

    MobileServiceTable table = mClient.getTable("STUDENTS", STUDENTS.class);
    table.insert(student, new TableOperationCallback() {
        @Override
        public void onCompleted(Object entity, Exception exception, ServiceFilterResponse response) {
            if (exception == null)
            {

            }
            else
            {

            }
        }
    });

But it always gives me this exception {"code":404,"error":"Error: Table 'STUDENTS' does not exist."}

Maybe it doesn't like my class structure? At this point I think that can be the only explanation to this problem. I do seem a bit confused about requiring Id in my class definitions, I figure it will be auto-generated for me. Also, here is my table definition in SQL.

CREATE TABLE [dbo].[STUDENTS] (
[email]       NVARCHAR (50) NOT NULL,
[password]    NVARCHAR (50) NOT NULL,
[FirstName]   NVARCHAR (50) NOT NULL,
[LastName]    NVARCHAR (50) NOT NULL,
[PhoneNumber] NVARCHAR (50) NOT NULL,
PRIMARY KEY CLUSTERED ([email] ASC));

Upvotes: 1

Views: 857

Answers (2)

Dillon Drobena
Dillon Drobena

Reputation: 921

So the issue ending up being that I didn't change the schema of my database. The database was already created before I made this mobile service, and I thought I could simply export that database and it would be supported by the service. Also, I forgot to insert an "id" column in all of my tables.

The easiest way I fixed this was by going into my azure management portal and created new tables from their webpage directly, and then went to my SQL editor to add the extra fields that I wanted, so now everything works great!

Here an article explaining the how to use an existing database for azure mobile services http://chrisrisner.com/Connecting-an-Existing-Database-to-Windows-Azure-Mobile-Services

Upvotes: 1

Boldbayar
Boldbayar

Reputation: 875

Did you create List to insert params to db?

MobileServiceTable<TodoItem> table = mClient.getTable(TodoItem.class);
List<Pair<String, String>> queryParams = new ArrayList<Pair<String, String>>();
queryParams.add(new Pair<String, String>("option", "value"));
table.insert(todoItem, queryParams, new TableOperationCallback<TodoItem>() {
    public void onCompleted(TodoItem inserted, Exception error, ServiceFilterResponse response) {

    }
});

Upvotes: 0

Related Questions