Skullomania
Skullomania

Reputation: 2215

How do I resolve my Invalid object name 'dbo.AspNetUsers' error?

I changed my connection string when starting a new mvc project because I needed to use some info out of an existing database. Now I get a "Invalid object name 'dbo.AspNetUsers' when I try to load the startup page. A quick google search says the issue happens because you are connecting to an existing database using asp.net users. Still, this should not occur since I am not using code first migrations, right? What is more, I am using Active Directory to authenticate my users instead of individual user accounts.

In addition, the AspNetUserstable does not exist in the database I am calling in the web.config:enter image description here

Upvotes: 1

Views: 7033

Answers (1)

Skullomania
Skullomania

Reputation: 2215

Due to the fact that I am not using the UserStore or the ApplicationUser provided by the Individual User Accounts defaults I needed to change this:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>

to

public class ApplicationDbContext : DbContext

Optionally If you are using Code First Migrations you could add the initial migrations, remove all of the sql code from the up and down methods, and finally update the database. Even though the tables will still not exist it seems to satisfy the compiler and your project as the error goes away and the page loads as expected.

Upvotes: 3

Related Questions