0

I have a requirement where i need to create users in two databases and i'm able to do that but,considering a use case where the user is successfully created in db1 and due to some server error the user is not created in db2.how should i handle this use case.EF6 provides transactions but, are those are only limited to Sp's?.How should i handle this scenario.

below is the code that i'm using on save changes:

public void SaveChanges()
        {
            using (var scope = new TransactionScope(TransactionScopeOption.Required,
                                                    new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
            {
                ((IObjectContextAdapter)db1Context).ObjectContext.SaveChanges(SaveOptions.DetectChangesBeforeSave);
                ((IObjectContextAdapter)db2Context).ObjectContext.SaveChanges(SaveOptions.DetectChangesBeforeSave);

                scope.Complete();
                ((IObjectContextAdapter)db1Context).ObjectContext.AcceptAllChanges();
                ((IObjectContextAdapter)db2Context).ObjectContext.AcceptAllChanges();

            }
        }
Surya Deepak
  • 419
  • 5
  • 16

1 Answers1

0

My answer to this would be... Don't.

You should be using something like SQL Server's replication depending on which database you're actually using. This will let the DB worry about keeping each instance consistent so you don't have to.

phuzi
  • 12,078
  • 3
  • 26
  • 50