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 8883297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:46:48+00:00 2026-06-14T20:46:48+00:00

MVC4, EF5, code first, VS Express 2012, Win 7 Pro When I move the

  • 0

MVC4, EF5, code first, VS Express 2012, Win 7 Pro

When I move the

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);

to the Application_Start of the Global.asax.cs (I’ve tried before and after the xxxConfig. files)
I get the following error message.

Cannot attach the file ‘D:\DevProj\MVC4Test\MVC4Tst\App_Data\aspnet-MVC4Test-20121123150620.mdf’ as database ‘aspnet-MVC4Test-20121123150620’

It runs fine from the InitializeSimpleMembershipAttribute and I deleted all LocalDB databases through SSMS. It is a new MVC4 internet project using all the defaults (installed VS 2012 Express two days ago). The only thing that has been edited is moving the WebSecurity.InitializeDatabaseConnection, excluding the InitializeSimpleMembershipAttribute from the project and commenting out references to it in the AccountController.

Any help appreciated.

  • 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-14T20:46:49+00:00Added an answer on June 14, 2026 at 8:46 pm

    The SimpleMembership DB has to exist before running

    WebSecurity.InitializeDatabaseConnection("AccountDB", "UserProfile",
                  "UserId", "UserName", autoCreateTables: true);
    

    Once the SM DB has been created (say through migration) best practice in MVC4 is to wrap the call to WebSecurity in the Application_Start section of the Global.asax.cs.

     WebSecConfig.RegisterWebSec();
    

    Place the WebSecConfig.cs file in the App_Start folder.

    WebSecConfig.cs

    using WebMatrix.WebData;
    
    namespace MVC4Test
    {
      public static class WebSecConfig
      {
        public static void RegisterWebSec() {
          WebSecurity.InitializeDatabaseConnection("AccountDB", "UserProfile",
                  "UserId", "UserName", autoCreateTables: true);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using MVC4 beta and entity framework. I am using code first design
I'm writing a MVC4 Website using Microsoft Visual Studio express 2012 for web. Whenever
MVC4 code first applicaiton I will be adding two int16 fields to the UseProfile
I am using EF5 codefirst in an ASP.NET MVC4 app. I have products and
Using MVC4 and EF5 codefirst. Got a problem whereby when creating a new data
In an MVC4 C# website, we are using Unit Testing to test our code.
I created MVC4 Mobile Application using VS 2012 default template. It's working fine in
I have an MVC 4 project using EF 5 Code First. I am trying
I just upgraded my MVC4 project to .NET 4.5 and EF5 and started using
I am making an MVC4 web application using Entity Framework 5 (Database-first with generated

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.