Use SQL Server Compact with ASP.NET Identity

h bob

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?

h bob

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get current identity number of specific table in sql server compact

From Dev

Does new ASP.NET MVC identity framework work without Entity Framework and SQL Server?

From Dev

Entity Framework: Setting correct connection string to SQL Server Compact in ASP.NET MVC 4

From Dev

Details of customizing ASP.NET Identity (OWIN) use of Entity Framework

From Dev

Thread.CurrentPrincipal.Identity in ASP .NET - is it safe to use

From Dev

ASP.NET identity use email instead of user name

From Dev

DbContext not initializing with SQL Server Compact in ASP.Net MVC

From Dev

ASP.Net Identity - Use custom Schema

From Dev

Web API and ASP.Net Identity with SQL Server and not LocalDB

From Dev

What is the best to use with developing Windows phone 8, SQL Server Express or SQL Server Compact or SQLite?

From Dev

Connect to Sql Server Compact Remotely

From Dev

Does ASP.NET Identity 2 use machinekey to hash the password?

From Dev

Use SQL Server Compact with ASP.NET Identity

From Dev

Use PasswordHasher without implementing Asp.Net Identity framework

From Dev

how to use asp.net Identity 2.0 with old database

From Dev

What is the use of asp.net identity .GenerateUserToken()

From Dev

Use asp.net identity in business layer and add properties

From Dev

ASP.NET Identity with db on cloud server

From Dev

IDENTITY_INSERT and SQL Server Compact

From Dev

ASP.NET Identity session expires too fast on prod server

From Dev

Azure AD and ASP.NET Identity + OWIN, which approach to use?

From Dev

How to get current identity number of specific table in sql server compact

From Dev

ASP.NET with SQL Server

From Dev

Does new ASP.NET MVC identity framework work without Entity Framework and SQL Server?

From Dev

connecting to sql server compact

From Dev

what kind of developers use SQL Server Compact

From Dev

How to use SQL Server Profiler in SQL Server with your ASP.NET application?

From Dev

Use both, SQL Server Compact and SQL Server with Entity Framework simultaneously

From Dev

Use Sql Server Compact Edition Database File in ReportViewer .Net 4.0

Related Related

  1. 1

    How to get current identity number of specific table in sql server compact

  2. 2

    Does new ASP.NET MVC identity framework work without Entity Framework and SQL Server?

  3. 3

    Entity Framework: Setting correct connection string to SQL Server Compact in ASP.NET MVC 4

  4. 4

    Details of customizing ASP.NET Identity (OWIN) use of Entity Framework

  5. 5

    Thread.CurrentPrincipal.Identity in ASP .NET - is it safe to use

  6. 6

    ASP.NET identity use email instead of user name

  7. 7

    DbContext not initializing with SQL Server Compact in ASP.Net MVC

  8. 8

    ASP.Net Identity - Use custom Schema

  9. 9

    Web API and ASP.Net Identity with SQL Server and not LocalDB

  10. 10

    What is the best to use with developing Windows phone 8, SQL Server Express or SQL Server Compact or SQLite?

  11. 11

    Connect to Sql Server Compact Remotely

  12. 12

    Does ASP.NET Identity 2 use machinekey to hash the password?

  13. 13

    Use SQL Server Compact with ASP.NET Identity

  14. 14

    Use PasswordHasher without implementing Asp.Net Identity framework

  15. 15

    how to use asp.net Identity 2.0 with old database

  16. 16

    What is the use of asp.net identity .GenerateUserToken()

  17. 17

    Use asp.net identity in business layer and add properties

  18. 18

    ASP.NET Identity with db on cloud server

  19. 19

    IDENTITY_INSERT and SQL Server Compact

  20. 20

    ASP.NET Identity session expires too fast on prod server

  21. 21

    Azure AD and ASP.NET Identity + OWIN, which approach to use?

  22. 22

    How to get current identity number of specific table in sql server compact

  23. 23

    ASP.NET with SQL Server

  24. 24

    Does new ASP.NET MVC identity framework work without Entity Framework and SQL Server?

  25. 25

    connecting to sql server compact

  26. 26

    what kind of developers use SQL Server Compact

  27. 27

    How to use SQL Server Profiler in SQL Server with your ASP.NET application?

  28. 28

    Use both, SQL Server Compact and SQL Server with Entity Framework simultaneously

  29. 29

    Use Sql Server Compact Edition Database File in ReportViewer .Net 4.0

HotTag

Archive