5

I'm using the latest ASP.NET MVC, Identity and Entity Framework.

The sample Identity project uses Sql Server Express. I want to use Sql Server Compact.

What I did:

  • Created a new empty solution (not MVC template)

  • Installed sample project: Install-Package Microsoft.AspNet.Identity.Samples -Pre

  • Installed: Install-Package Microsoft.SqlServer.Compact

  • Installed: Install-Package EntityFramework.SqlServerCompact

  • Changed default connection string in web.config to:

    <add name="Foo" 
         providerName="System.Data.SqlServerCe.4.0" 
         connectionString="Data Source=|DataDirectory|\Foo.sdf;" />
    
  • Changed ApplicationDbContext to use the Foo connection string:

    ApplicationDbContext() : base("name=Foo", false)
    

Problem is, when ApplicationDbContext is accessed for the first time (during seeding, in the ApplicationDbInitializer.InitializeIdentityForEF() method):

  • the database is created
  • I get an InvalidOperationException: UserId not found for the line result = userManager.SetLockoutEnabled(user.Id, false);

I thought it would be as simple as changing the connection string - so what am I doing wrong? Or put differently, how do I convert the solution from SQL Server Express to SQL Server Compact?

1
  • 1
    I've followed your instructions and everything works correctly. Commented Sep 6, 2014 at 22:23

1 Answer 1

4

Found the error. My connection string was wrong, I had:

<add name="Foo"
     providerName="System.Data.SqlServerCe.4.0"
     connectionString="
       Data Source=|DataDirectory|\Foo.sdf;
       Persist Security Info=false;
       "/>

which doesn't work (XML, so thought whitespace is ignored, it's not), whereas this does:

<add name="Foo"
     providerName="System.Data.SqlServerCe.4.0"
     connectionString="Data Source=|DataDirectory|\Foo.sdf;Persist Security Info=false;" />

Regardless, the question itself contains a step-by-step for using sqlce with Identity2. Maybe it'll help someone.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.