locked
Problem with FK in the Schema RRS feed

  • 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&#xD;
    Error occurred writing output response. Multiple entries have the same primary key.&#xD;
       at Microsoft.Synchronization.Services.UploadChangesRequestProcessor.GetSyncWriterWithContents() in C:\syncopensrc\src\SyncServiceLib\RequestProcessor\UploadChangesRequestProcessor.cs:line 389&#xD;
       at Microsoft.Synchronization.Services.UploadChangesRequestProcessor.ProcessRequest(Request incomingRequest) in C:\syncopensrc\src\SyncServiceLib\RequestProcessor\UploadChangesRequestProcessor.cs:line 141&#xD;
       at Microsoft.Synchronization.Services.SyncService`1.ProcessRequestForMessage(Stream messageBody) in C:\syncopensrc\src\SyncServiceLib\SyncService.cs:line 154&#xD;
    &#xD;
    &#xD;
    </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

  • Wednesday, 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&#xD;
    Incorrect syntax near the keyword 'End'.&#xD;
       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)&#xD;
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()&#xD;
       at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)&#xD;
       at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()&#xD;
       at System.Data.SqlClient.SqlDataReader.get_MetaData()&#xD;
       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)&#xD;
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)&#xD;
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)&#xD;
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)&#xD;
       at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)&#xD;
       at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)&#xD;
       at Microsoft.Synchronization.Services.SqlProvider.SqlSyncProviderService.GetCurrentServerVersionForEntities(IEnumerable`1 entities, SqlConnection connection, SqlTransaction transaction) in C:\syncopensrc\src\SyncServiceLib\SqlProvider\SqlSyncProviderService.cs:line 196&#xD;
       at Microsoft.Synchronization.Services.SqlProvider.SqlSyncProviderService.SqlSyncProviderApplyChangeFailed(Object sender, DbApplyChangeFailedEventArgs e) in C:\syncopensrc\src\SyncServiceLib\SqlProvider\SqlSyncProviderService.cs:line 813&#xD;
       at Microsoft.Synchronization.Data.RelationalSyncProvider.GetConflictAction(DbSyncConflict conflict, Exception error, IDbTransaction transaction)&#xD;
       at Microsoft.Synchronization.Data.ChangeHandlerBase.ApplyChange(FailedDeleteDelegate_type failedDeleteDelegate)&#xD;
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChangesInternal(DbSyncScopeMetadata scopeMetadata, IDbTransaction transaction, FailedDeleteDelegate_type failedDeleteDelegate, DataSet dataSet, ChangeApplicationType applyType)&#xD;
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChanges(DbSyncScopeMetadata scopeMetadata, IDbTransaction applyTransaction, DataSet dataSet, DbSyncSession DbSyncSession, Boolean commitTransaction, FailedDeleteDelegate_type failedDeleteDelegate, String batchFileName, ChangeApplicationAction&amp; action)&#xD;
       at Microsoft.Synchronization.Data.RelationalSyncProvider.SingleTransactionApplyChangesAdapter.Apply(DataSet dataSet, Boolean commitTransaction, FailedDeleteDelegate_type failedDeleteDelegate, String batchFileName, ChangeApplicationAction&amp; action)&#xD;
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ApplyChanges(DbSyncScopeMetadata scopeMetadata, DataSet dataSet, DbSyncSession dbSyncSession, Boolean commitTransaction)&#xD;
       at Microsoft.Synchronization.Data.RelationalSyncProvider.ProcessChangeBatch(ConflictResolutionPolicy resolutionPolicy, ChangeBatch sourceChanges, Object changeDataRetriever, SyncCallbacks syncCallbacks, SyncSessionStatistics sessionStatistics)&#xD;
       at Microsoft.Synchronization.Services.SqlProvider.SqlSyncProviderService.ApplyChanges(Byte[] serverBlob, List`1 entities) in C:\syncopensrc\src\SyncServiceLib\SqlProvider\SqlSyncProviderService.cs:line 594&#xD;
       at Microsoft.Synchronization.Services.UploadChangesRequestProcessor.ProcessRequest(Request incomingRequest) in C:\syncopensrc\src\SyncServiceLib\RequestProcessor\UploadChangesRequestProcessor.cs:line 130&#xD;
       at Microsoft.Synchronization.Services.SyncService`1.ProcessRequestForMessage(Stream messageBody) in C:\syncopensrc\src\SyncServiceLib\SyncService.cs:line 154&#xD;
    &#xD;
    &#xD;
    </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