Use SQL Server Compact with ASP.NET Identity

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

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

What I've done:

  • Created a new empty solution (not MVC pattern)

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

  • Installed: Install-Package Microsoft.SqlServer.Compact

  • Installed: Install-Package EntityFramework.SqlServerCompact

  • Changed the default connection string to web.config

    before:

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

  • Changed ApplicationDbContext

    to use connection string Foo

    :

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

The problem is when it ApplicationDbContext

opens for the first time (during seeding in the method ApplicationDbInitializer.InitializeIdentityForEF()

):

  • database is created
  • I am getting InvalidOperationException: UserId not found

    for lineresult = userManager.SetLockoutEnabled(user.Id, false);

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

+3


source to share


1 answer


An error was detected. 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 missed thoughts are ignored, 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 guide for using sqlce with Identity2. Maybe this will help someone.

+3


source







All Articles