Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8349767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:06:34+00:00 2026-06-09T08:06:34+00:00

I am new to asp .net mvc3 I am trying to store additional user

  • 0

I am new to asp .net mvc3

I am trying to store additional user information over the standard asp .net membership provider. I have created a new entity UserAddress and I sync it with the aspnet_tables using the membership API.

However, now if I make any changes to the UserAddress class – asp.net does not drop and recreate the model. I get the error

Cannot drop database because it is in use.

I have searched stackoverflow and google. Basically, my problem is similar to this

Database in use error with Entity Framework 4 Code First

However, I am not sure how to implement what chris suggest as a solution:

“This was happening to me because I was calling Membership methods against the DB and that was creating a conflict. I resolved this by forcing the initializer to run and seed before using the Membership system”

I am pretty sure this is the reason why the database is in use because my code falls over at this point in the data repository:

var userid = Membership.GetUser.ProviderUserKey.ToString();
return db.UserAddress.SingleOrDefault(a => a.UserId == userid);

How can I force the initializer to run before membership system?

Snippet of my code is below:

public class UserAddress
{
    public int UserAddressId { get; set; }
    public string UserId { get; set; }
    public string FlatNo { get; set; }
    public string BuildingName { get; set; }
    public string Address1 { get; set; }
    public string Address2 { get; set; }
    public string PostCode { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string Country { get; set; }
    public long MobilePhone { get; set; }
}

public class NPLHWebsiteDb : DbContext
{
    public DbSet<UserAddress> UserAddress { get; set; }
}

public class NPLHWebsiteInitializer : DropCreateDatabaseIfModelChanges<NPLHWebsiteDb>
    {
        protected override void Seed(NPLHWebsiteDb context)
        {
            var userAddress = new List<UserAddress>
            {
                new UserAddress {
                    UserAddressId = 1,
                    UserId = "153",
                    FlatNo = "6.4",
                    BuildingName = "Wilton Plaza",
                    MobilePhone = 9810110123,
                }
            };
            userAddress.ForEach(a => context.UserAddress.Add(a));
            context.SaveChanges();
    }

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T08:06:36+00:00Added an answer on June 9, 2026 at 8:06 am

    As suspected the culprit was ‘Membership’.

    The code uses membership to look up the address for the logged in user. Therefore, if I logged in the website then my Membership tables would get called and SQL would not allow the initalizer to drop and recreate table as it is currently in use (i.e. by Membership).

    This is exactly what Chris pointed in stack overflow question I had linked to in my original question

    Basically, the solution was to force the database to initalize before Membership is called. I was not sure how to do that. I was trying to do in manually by entering the URL to access the user address page. However, that was not working as it again failed at the line which calls membership tables.

    The correct way to do this was to force the initialization in Application start as follows:

    System.Data.Entity.Database.SetInitializer(new MyInitializer());          
    MyContext db = new MyContext();         
    db.Database.Initialize(true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to test my asp.net mvc3 custom membership provider. I can't seem to
i have a problem with the asp.net MVC3. when i create a new project
I have a new asp.net mvc project and i am trying to figure out
I am new to ASP.NET MVC3 and trying desperately to just get something simple
I am new to asp.net mvc3 and trying to get a connection going to
Im new at Asp.Net MVC3, and i was trying to use CKEditor. But can't
Firstly, I'm new to MVC - and trying out ASP.NET MVC3. I want to
I have installed MVC 3 and now I'm trying to follow these steps: http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-1
I'm new in asp.net mvc3 programming and I'm trying to build a specific form.
I'm building a new Asp.Net MVC3 solution and would like to have all the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.