2

I have a situation where I use SQL server transactional replication from my main database to my failover database. I have a main site and my fail over website is using my failover database.

Both websites (use entity framework) are identical (so are databases hopefully).

My problem is that some operations crash on my failover website if my replication is active. Once I deactivate my replication, the operation goes through normally.

My guess is there is some concurrency issue between the EntityModel of my fail over website and the database when exposed to replication.

Has anyone encountered similar issues? Anyone with experience with transactional replication + entity framework ?

Here is the exception I get:

at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, 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 Library.XXXXEntities.Context_SavingChanges(Object sender, EventArgs e) 
in C:\SVN\Branches\Prod - 1.68.7\Library\LINQ\Audit.cs:line 38 
at System.Data.Objects.ObjectContext.OnSavingChanges() 
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options) 
at System.Data.Objects.ObjectContext.SaveChanges() at Library.Provider.Save() 
in C:\SVN\Branches\Prod - 1.68.7\Library\XXXX.Provider.cs:line 57 
at XXXX.mnuExportGeneric.RecreatePositionsToBeUnique() 
at XXXX.mnuExportGeneric.Export(Int32 programId, DirectoryInfo directoryDestination, Boolean exportInventory, Int32 CurrencyListID, Int32 configurationId, Boolean subFolder) 
at XXXX.mnuExport.Export(Int32 ProgramId, String TempExportFolder, String ExportFolder, TreeView treeViewErreurs, Int32 CurrencyListID, Boolean exportInventory, Int32[] configurationsId) 

There seams to be a problem with the mapping, but only when the transactional replication is active.

Update: I've come out completely of my application environnement and simply trying to insert a new row in a table in my failover database when the replication is "existing" not just active seams to be illegal. Tomorow I'll try with the replication completely removed... or more drastic changes like that...

Thanks!

Sébastien Richer
  • 1,642
  • 2
  • 17
  • 38
  • Why do you execute changes on failover application? That changes will not be reflected back in the main database. What type of exception do you get and what concurrency check is your entities using? – Ladislav Mrnka Apr 18 '11 at 20:56
  • I'm executing the changes on the fail over application as a safety measure to check that everything is working correctly. The operation I'm launching is a standard "business" operation. And my entities are using the default concurrency check (I think that is AppendOnly). – Sébastien Richer Apr 18 '11 at 21:11

1 Answers1

1

This is probably not a problem with EF but more a problem with your replication setup.

SQL Server does allow for replications where changes can be made at any node, but this requires enterprise edition, see: http://technet.microsoft.com/en-us/library/ms151196.aspx

It may be that you are trying to update a readonly replica.

Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252
  • Indeed, I have been reading up and Transactionnal Replication makes my replicated database read-only. I saw the special stored procedures that the replication process uses. I guess it makes sense. Thanks! – Sébastien Richer Apr 27 '11 at 12:39