Unable to add a new record to Azure SQL table
I had been received an error when try to add a new record to Azure SQL table via Mobile App service in a mobile app as below:
StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: 400 Bad request"
StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers: 400 Bad request"
I verified the SQL table and even can manually insert a record on there.
Suddenly, I realized that an error
" System.Data.SqlClient.SqlException (0x80131904): Cannot create more than one clustered index on table" was showing when created this table in Azure Mobile .Net back-end.
Generally, this error message is caused that Entity Framework does not have an annotation for creating a clustered index that is not a primary key, so the mobile server SDK manually creates the right SQL statements to set CreatedAt as a non-primary key clustered index.
To resolve this, In the Migrations\Configuration.cs file, include the following lines:
public Configuration()
{
AutomaticMigrationsEnabled = false;
SetSqlGenerator("System.Data.SqlClient", new EntityTableSqlGenerator());
}
I updated my Azure SQL table again based on above configuration. Now I can insert data to table successfully.
" System.Data.SqlClient.SqlException (0x80131904): Cannot create more than one clustered index on table" was showing when created this table in Azure Mobile .Net back-end.
Generally, this error message is caused that Entity Framework does not have an annotation for creating a clustered index that is not a primary key, so the mobile server SDK manually creates the right SQL statements to set CreatedAt as a non-primary key clustered index.
To resolve this, In the Migrations\Configuration.cs file, include the following lines:
public Configuration()
{
AutomaticMigrationsEnabled = false;
SetSqlGenerator("System.Data.SqlClient", new EntityTableSqlGenerator());
}
I updated my Azure SQL table again based on above configuration. Now I can insert data to table successfully.
Comments
Post a Comment