Search code examples
c#azureasp.net-identityhigh-availabilityfailover

Azure Failover Groups and IdentityDbContext


Having a strange issue with Azure Failover Groups for our DB, and IdentityDbContext (AspNet Identity).

If I set the connection string to the failover group, I receive a login failed error in the logs, however if I connect directly to the primary or secondary servers, the login succeeds.

The other strange part is that this only seems to happen with IdentityDbContext. If I use just a normal DB context for a test, the login works fine with the failover group connection string, if I use new SqlConnection, it also works fine, but when I try to use IdentityDbContext -> Login failed.

I know when connecting to a failover group from SSMS, you need to specify a default DB since it has no access to master, but in my connection string I have a DB specified so I'm not sure if that could be the problem.

Has anyone else encountered this? I feel like it's strange that this would only be happening to myself.

This is in .NET 4.6.1 with the latest version of Microsoft.AspNet.Identity (2.2.1)


Solution

  • In the end I found the issue thanks to this blog post:

    http://www.morganskinner.com/2014/04/optimizing-aspnet-identity-database.html

    Even though technically the blog post has nothing to do with Failover groups, it does point out the fact that IdentityDbContext does a check against sys.databases and other "master" db operations which are unavailable in the Failover group.

    So the reason it was working with normal DBContexts, and SqlConnections was because theses hidden checks were not being performed. A

    Since I don't need the IdentityDbContext to do these checks, simply setting the second parameter of the base call to false in order to by pass this functionality solved the issue.

    Ex: public AuthenticationContext(): base(<connection string id>,false)