Dotmim.Sync: Table Doest not have PK Exception, but table does have PK

I have a web server setup. That runs Deprovision and Provision.

var syncProvider =
              new SqlSyncProvider(
                  Configuration
                      .GetConnectionString(
                          "SStGConnection")); // serviceScope.ServiceProvider.GetService<SqlSyncProvider>();

          // delete triggers and sp
          var syncSet = new SyncSet();
          syncSet.Tables.Add(BaseDbContext.SyncTables);

          await syncProvider.DeprovisionAsync(syncSet,
              SyncProvision.StoredProcedures | SyncProvision.Triggers);

          UpdateDatabaseLogDatabase(app);
          UpdateDatabaseSStGDatabase(app);
          UpdateDatabaseCommunicationDatabase(app);

          await syncProvider.ProvisionAsync(syncSet,
              SyncProvision.StoredProcedures | SyncProvision.Triggers);

The updateDatabase(*) statements run EFCore 3 migrations. Then when this line runs

await syncProvider.ProvisionAsync(syncSet, SyncProvision.StoredProcedures | SyncProvision.Triggers);

the exception below gets thrown

Table AVBActivityQuestion does not have any primary key.

but the table does have a PK

/****** Object:  Table [AVB].[AVBActivityQuestion]    Script Date: 3/16/2020 7:17:29 AM ******/
CREATE TABLE [AVB].[AVBActivityQuestion](
	[Id] [smallint] IDENTITY(1,1) NOT NULL,
	[Question] [nvarchar](256) NOT NULL,
	[AnswerType] [nvarchar](16) NOT NULL,
	[QuestionForActivityType] [nvarchar](64) NOT NULL,
	[Hint] [nvarchar](256) NULL,
	[CreatedAt] [datetimeoffset](7) NOT NULL,
	[ModifiedAt] [datetimeoffset](7) NULL,
	[IsActive] [bit] NOT NULL,
	[IsDeleted] [bit] NOT NULL,
 CONSTRAINT [PK_AVBActivityQuestion] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

ALTER TABLE [AVB].[AVBActivityQuestion] ADD  DEFAULT (getutcdate()) FOR [CreatedAt]
GO

ALTER TABLE [AVB].[AVBActivityQuestion] ADD  DEFAULT (getutcdate()) FOR [ModifiedAt]
GO

This is also the initial setup and provisioning of the DB. None of the Sync objects (triggers, tables,etc) exist in the current database. It is the 1st run of the Web Server project that will host the data sync endpoint.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

Depending on what you want from the server ?

if you need this:

// Create a remote orchestrator, to manage hub server database
var remoteOrchestrator = new RemoteOrchestrator(serverProvider, Config.GetClientOptions(), Config.GetSetup());

// Get schema from server side
var schema = await remoteOrchestrator.GetSchemaAsync();

You can replace with this:

// Create a remote orchestrator, to manage hub server database
var remoteOrchestrator = new WebClientOrchestrator("https://www.yourserver.com/api/sync");

// Get schema from server side
var schema = await remoteOrchestrator.GetSchemaAsync();

I won’t be able to solve ALL the scenario and problems that can occirs

LOL, i been in this business long enough to solving for everything is not a thing.

I was asking cause your experience might have some best practice methodologies. Realistically once the DB is mature, there or not sweeping changes like that. and if there big changes like that, each one will have its own unique conditions.

Im making the logic changes discussed above, will let you know of my success.