问题
I created an azure mobile service and set up all the database tables properly (tested them). However when I try to insert a record to my SQL table through my android app, the record doesn't get added. (Yes my SQL table is ready for the mobile service as well. Changed the Schema as well)
I don't get an error either.
Here's my code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_screen);
final String mobileServiceUrl =
"https://MY_AZURE_MOBILE_URL.net/tables/UserTable";
final String mobileServiceAppId =
"MY_MOBILESERVICE_APPID";
try {
// Create the Mobile Service Client instance, using the provided
// Mobile Service URL and key
mClient = new MobileServiceClient(
mobileServiceUrl,
mobileServiceAppId,
this);
// Get the Mobile Service Table instance to use
mToDoTable = mClient.getTable(UserTable.class);
} catch (MalformedURLException e) {
}
Button regiBtn = (Button) findViewById(R.id.signupDivertBtn);
regiBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try
{
UserTable user = new UserTable();
user.setPassword("111");
user.setFname("TESTName");
user.setId("234232");
user.setEmail("sear@tr.com");
mToDoTable.insert(user);
}
Why doesn't the mToDoTable.Insert() statement work? Is it not the right way to insert a record to an azure table?
EDIT:
Here's my UserTable Entity class:
public class UserTable {
@com.google.gson.annotations.SerializedName("id")
private String id;
@com.google.gson.annotations.SerializedName("Email")
private String email;
@com.google.gson.annotations.SerializedName("Password")
private String password;
@com.google.gson.annotations.SerializedName("UserFName")
private String fname;
public UserTable()
{
}
public UserTable(String id, String email, String password, String fname) {
this.setId(id);
this.setEmail(email);
this.setPassword(password);
this.setFname(fname);
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
回答1:
Before jumping into why your Android App is not working. I suggest you making sure that you could insert a record through API help first. You should be able to either test this through local debug or on your published azure site. Once that is working correctly and you are able to insert a record through API help. Then try what CSharpRocks mentioned.
Be aware that when you debug locally, you should setup a local DB like a SQL express server and change your web.config MS_TableConnectionString to match. And your mobile client URL in your client App(For example, Android) should be the local URL that pops up in the browser during debug.
回答2:
Your mobileServiceUrl value is wrong. It should point to the root of your mobile service like this "https://YOURSERVICENAME.azure-mobile.net/".
I would let the service set the ID (GUID) for you. If you don't like it, just add another field to store your own ID.
来源:https://stackoverflow.com/questions/29652413/azure-mobile-service-cannot-insert-any-records-to-table