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();

            }
        }
2

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.