Asked by:
Problem with FK in the Schema

Question
-
Hello, I am developing an application using HTML5 and javascript.
I have two entities in my data Base, "Entries" and "Hours", "Entries" has a PK "EntryId", and the "Hours" PK is "EntryId", that is a FK.
When I run the application, if I try add a new Hour, I add a new "Entries" in the webstorage, and then I add a new "hour" with the some EntryId. But the problem is at the moment os sync, using Fiddler I can see this error:
<ServiceError xmlns="http://schemas.datacontract.org/2004/07/Microsoft.Synchronization.Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><ErrorDescription>Microsoft.Synchronization.Services.SyncServiceException
 Error occurred writing output response. Multiple entries have the same primary key.
 at Microsoft.Synchronization.Services.UploadChangesRequestProcessor.GetSyncWriterWithContents() in C:\syncopensrc\src\SyncServiceLib\RequestProcessor\UploadChangesRequestProcessor.cs:line 389
 at Microsoft.Synchronization.Services.UploadChangesRequestProcessor.ProcessRequest(Request incomingRequest) in C:\syncopensrc\src\SyncServiceLib\RequestProcessor\UploadChangesRequestProcessor.cs:line 141
 at Microsoft.Synchronization.Services.SyncService`1.ProcessRequestForMessage(Stream messageBody) in C:\syncopensrc\src\SyncServiceLib\SyncService.cs:line 154
 
 
 </ErrorDescription></ServiceError>
In my shema the entities are defined as follows:
"HTML5SyncScope.Entries": { EntryId: { key: true }, ProjectId: {}, Date: {}, EmployeeId: {}, Description: {}, DateAdded: {} }, "HTML5SyncScope.Hours": { EntryId: { key: true }, Extra: {}, Start: {}, End: {}, Quantity: {} }
Can anyone help me?Thanks,
Santiago.-
Wednesday, December 14, 2011 10:28 AM
All replies
-
it think its a bug and someone has posted a quick fix here: http://social.msdn.microsoft.com/Forums/en-US/synclab/thread/7f2f54de-541c-4dbc-a77e-a7491782581dWednesday, December 14, 2011 1:11 PM
-
Thanks JuneT, I could solve my problem but now I have another. When the application is synchronizing the Server return the following error:
HTTP/1.1 500 Internal Server Error Content-Length: 4249 Content-Type: application/json Server: Microsoft-IIS/7.0 X-Powered-By: ASP.NET Date: Thu, 15 Dec 2011 11:54:41 GMT <ServiceError xmlns="http://schemas.datacontract.org/2004/07/Microsoft.Synchronization.Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><ErrorDescription>System.Data.SqlClient.SqlException
 Incorrect syntax near the keyword 'End'.
 at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
 at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
 at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, 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.ExecuteReader(CommandBehavior behavior)
 at Microsoft.Synchronization.Services.SqlProvider.SqlSyncProviderService.GetCurrentServerVersionForEntities(IEnumerable`1 entities, SqlConnection connection, SqlTransaction transaction) in C:\syncopensrc\src\SyncServiceLib\SqlProvider\SqlSyncProviderService.cs:line 196
 at Microsoft.Synchronization.Services.SqlProvider.SqlSyncProviderService.SqlSyncProviderApplyChangeFailed(Object sender, DbApplyChangeFailedEventArgs e) in C:\syncopensrc\src\SyncServiceLib\SqlProvider\SqlSyncProviderService.cs:line 813
 at Microsoft.Synchronization.Data.RelationalSyncProvider.GetConflictAction(DbSyncConflict conflict, Exception error, IDbTransaction transaction)
 at Microsoft.Synchronization.Data.ChangeHandlerBase.ApplyChange(FailedDeleteDelegate_type failedDeleteDelegate)
 at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChangesInternal(DbSyncScopeMetadata scopeMetadata, IDbTransaction transaction, FailedDeleteDelegate_type failedDeleteDelegate, DataSet dataSet, ChangeApplicationType applyType)
 at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChanges(DbSyncScopeMetadata scopeMetadata, IDbTransaction applyTransaction, DataSet dataSet, DbSyncSession DbSyncSession, Boolean commitTransaction, FailedDeleteDelegate_type failedDeleteDelegate, String batchFileName, ChangeApplicationAction& action)
 at Microsoft.Synchronization.Data.RelationalSyncProvider.SingleTransactionApplyChangesAdapter.Apply(DataSet dataSet, Boolean commitTransaction, FailedDeleteDelegate_type failedDeleteDelegate, String batchFileName, ChangeApplicationAction& action)
 at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChanges(DbSyncScopeMetadata scopeMetadata, DataSet dataSet, DbSyncSession dbSyncSession, Boolean commitTransaction)
 at Microsoft.Synchronization.Data.RelationalSyncProvider.ProcessChangeBatch(ConflictResolutionPolicy resolutionPolicy, ChangeBatch sourceChanges, Object changeDataRetriever, SyncCallbacks syncCallbacks, SyncSessionStatistics sessionStatistics)
 at Microsoft.Synchronization.Services.SqlProvider.SqlSyncProviderService.ApplyChanges(Byte[] serverBlob, List`1 entities) in C:\syncopensrc\src\SyncServiceLib\SqlProvider\SqlSyncProviderService.cs:line 594
 at Microsoft.Synchronization.Services.UploadChangesRequestProcessor.ProcessRequest(Request incomingRequest) in C:\syncopensrc\src\SyncServiceLib\RequestProcessor\UploadChangesRequestProcessor.cs:line 130
 at Microsoft.Synchronization.Services.SyncService`1.ProcessRequestForMessage(Stream messageBody) in C:\syncopensrc\src\SyncServiceLib\SyncService.cs:line 154
 
 
 </ErrorDescription></ServiceError>
That happens when I am doing an add, when I am editing an existing entity its ok.Anyone have any ideas?
Thursday, December 15, 2011 12:17 PM -
have you tried running SQL Profiler to see that actual SQL statements being fired?Thursday, December 15, 2011 1:01 PM