I have used this link to add first name and last name. Now I'm seeing an error Cannot drop database "dbname" because it is currently in use..
I don't want to drop my Database, just want to add first name and last name in register of asp.net identity user in mvc5. give me suggestions..
DropCreateDatabaseAlways I was using this option. After changing to
Database.SetInitializer<ApplicationDbContext>(new
MigrateDatabaseToLatestVersion<ApplicationDbContext,
APPLICATION.Migrations.Configuration>());
This works fine, also I need to enable migration using package manager console
Enable-Migrations
Add-Migration "FirststName"
Add-Migration "LastName"
Thanks #Archana Parmar
Related
I'm trying to add Identity to an existing and working MVC project.
When used this command Add-Migration CreateIdentitySchema I got error message: 'More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.' and I chose the existing DB context that I have previously created for the main functionality of the application and now it shows 'There is already an object named 'ExpenseReport' in the database.' so it's trying to recreate my initial model.
Should I have a separate DB Context for Identity and if yes how to connect user to data from the other context?
So, i think you can use several DbContexts with different connections (just need to write it in your Startup class) or you need to use pattern "DbContext Factory". You can read more here .
Hope it will help you.
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:
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.
I have no experience with web hosting. This would be my first application to host.I have an MVC 5 application with Entity Framework. It is locally using two DBs, the one that I created (BailBond) and the default one named "aspnet-BailBondMS-20160913064154" because my project name is BailBondMS. When I publish it winhost, the default DB is not connected to the application. I manually tried to create a DB in my site database in winhost with the same name but it wont let me do it because the name is too long. I then shortened the name. The problem now is that I cannot update the default DB name in Visual Studio to match the one in my control panel in winhost.
What should I do? What am I doing wrong? Thank you for your help.
I went to upgrade our ASP.NET Web Forms solution from Identity 1.x to Identity 2.0. I updated the three Identity 2.0 packages. I then went to work on implementing Password Reset, etc. I didn't realize I had to Update the Database. That migration failed because the tables were in the wrong context. We decided to start over. We deleted the tables but they are not getting recreated when I access the Login page. How do I get these tables regenerated or should I create them manually?
Try disabling the schema consistency. This is one time thing that needs to happen when you upgrade asp.net identity from version 1.0 to 2.0.
public ApplicationDbContext() : base("MyConnection", throwIfV1Schema:false)
Notice I added throwIfV1Schema:false as a second parameter. Compile it, try to log in so the DB gets updated, do the migrations if needed and then you can remove it.
I am trying to understand the SimpleMembershipProvider in detail. So far, I have created a new project in VWD-2012 with an empty Asp.Net MVC - 4 template.
I have been following this great tutorial. I was able to just copy and paste all the classes from this tutorial into my project. I then used the following line of code in my global.asax Application_Start method to initialize the SimpleMembershipProcider :
WebSecurity.InitializeDatabaseConnection("dbcontext", "UserProfile", "Id", "Name", true);
(I am using Id and Name as a column name in my userprofile table)
After that I enabled migration in my project, created the initial migration and then Update-Database. Then I check my database in visual studio and all classes related to SimipleMembership were formed.
Then I create a user and successfully logged in. Up to this point everything was working fine. I then added Facebook as an identity provider on my website. In this process when the code line
OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
trys to create an entry in webpages_OAuthMembership table. However the following exception was raised:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.webpages_OAuthMembership_dbo.webpages_Membership_UserId". The conflict occurred in database "dbcontext", table "dbo.webpages_Membership", column 'UserId'.
The statement has been terminated.
Can anybody please help me solve this issue?