ASP.NET MVC4 Project + SQL CE 4 limitations

With the official RTM release of Visual Studio 2012 and the MVC 4 project (also available for VS 2010), I have been using some of the features of new features and out of the box features of hte MVC 4 project to ease the development of my user stories.

SQL CE 4 made database backends much simpler by allowing developers to utilize a SQL engine even if you don’t have it installed on your computer and the zero-config usage is great. SQL CE does have some its limitations and the OAuthWebSecurity class  exposes one such limitation: Transasction Scopes.

Given a development environment with a SQL CE 4 database, you can register a number of authentication providers such as Facebook and Google out of the box with no issues.

Dictionary<String,Object> facebookPermissions = new Dictionary<string,object>() ;
facebookPermissions.Add( "scope", "email" );
OAuthWebSecurity.RegisterFacebookClient(
  appId: "My Facebook App ID",
  appSecret: "My Facebook App Secret",
  displayName: "Facebook",
  extraData: facebookPermissions
);

OAuthWebSecurity.RegisterGoogleClient();

The limitation materializes when trying to disassociate the authentication provider (in this case, Google) from the base account. If you are using SQL CE 4 and the code made available to you with the out of the box ASP.NET MVC 4 project, you will get the following error when attempting to disassociate the account with the OAuth provider.

The connection object can not be enlisted in transaction scope.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The connection object can not be enlisted in transaction scope.

Source Error:

Line 110: using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.Serializable }))
Line 111: {
Line 112:  bool hasLocalAccount = OAuthWebSecurity.HasLocalAccount(WebSecurity.GetUserId(User.Identity.Name));
Line 113:   if (hasLocalAccount || OAuthWebSecurity.GetAccountsFromUserName(User.Identity.Name).Count > 1)
Line 114:   {