500 internal server error - JQuery Ajax call to Wcf data service
-
Wednesday, May 18, 2011 5:39 PM
Hi,
I have the following data model on service side -
public class X
{
public int x_id { get; set; }
public string name { get; set; }
public DateTime create_dt { get; set; }
public List<Y> ylist { get; set; }
}
I am trying to do simple insert using HTTP Post in JQuery Ajax as follws but I get a 500 error.
var data = { name: $("#name").val()};
// JSONify the data
var data = JSON.stringify(data);
// Post it
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "http://localhost:3392/DataTest.svc/X",
data: data,
dataType: "json",
success: insertXCallback
});
As you can see X has other properties and is lnked to Y table for which I am not passing any data because I have set create_dt column on SQL Server to use getdate() by default when doing any row insert, and for Y I don't want to pass any data in this call.
How can I fix this error?
Please advise
All Replies
-
Wednesday, May 18, 2011 6:02 PMAnswerer
It would help if you can get the exact error on the server side. Follow this post http://blogs.msdn.com/b/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx to get the call stack and message.
Regards,
PQ
Peter Q. http://blogs.msdn.com/peter_qian -
Wednesday, May 18, 2011 6:06 PM
It would help if you can get the exact error on the server side. Follow this post http://blogs.msdn.com/b/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx to get the call stack and message.
Regards,
PQ
Peter Q. http://blogs.msdn.com/peter_qianThanks Peter. I found the problem but still looking for a solution. I replaced this
var data = { name: $("#name").val()};
with the following:
var data = { name: $("#campaignname").val(), create_dt: '2011-05-18 17:15:45' };
and it worked. Meaning it wants the date in correct format.
But I am setting this date in SQL Server anyways during the insert, so can I not pass null or not pass this property at all
Please advise.
-
Wednesday, May 18, 2011 6:34 PMAnswererHi, What exactly is the error thrown? What is the shape of your metadata? The server should happily ignore missing properties in payload mainly because of projected entities will not upload the full payload. So as long as the field is totally missing then it'll be fine.
Peter Q. http://blogs.msdn.com/peter_qian -
Wednesday, May 18, 2011 6:48 PM
Hi, What exactly is the error thrown? What is the shape of your metadata? The server should happily ignore missing properties in payload mainly because of projected entities will not upload the full payload. So as long as the field is totally missing then it'll be fine.
Peter Q. http://blogs.msdn.com/peter_qianThis is the exact error -
<message>The conversion of a datetime2 data type to a datetime data type resulted in an out-of-rangevalue.
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?><error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><code></code><message xml:lang="en-US">An error occurred while processing this request.</message><innererror><message>An error occurred while updating the entries. See the inner exception for details.</message><type>System.Data.UpdateException</type><stacktrace> at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManagerstateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Objects.ObjectContext.SaveChanges()
at System.Data.Services.Providers.ObjectContextServiceProvider.SaveChanges()
at System.Data.Services.UpdatableWrapper.SaveChanges()
at System.Data.Services.DataService`1.HandleNonBatchRequest(RequestDescription description)
at System.Data.Services.DataService`1.HandleRequest()</stacktrace><internalexception><message>The conversion of a datetime2 data type to a datetime data type resulted in an out-of-rangevalue.
The statement has been terminated.</message><type>System.Data.SqlClient.SqlException</type><stacktrace> at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReaderdataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnectionconnection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapteradapter)</stacktrace></internalexception></innererror></error> -
Wednesday, May 18, 2011 7:09 PM
Hi, What exactly is the error thrown? What is the shape of your metadata? The server should happily ignore missing properties in payload mainly because of projected entities will not upload the full payload. So as long as the field is totally missing then it'll be fine.
Peter Q. http://blogs.msdn.com/peter_qianThis is the problem and apparently i haven't founda way to resolve this other than changing my databases's column data type to datetime2, which I would hate to do.
Please suggest a solution to this.
-
Wednesday, April 18, 2012 4:33 AMHere Your Getting the Date Value as 01/01/0001 That's why you are Getting that Error. Once check Date Time Column value .

