Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create MVC4 Membership Database

I'm familiar with aspnet_regsql.exe to create a membership database (it produces 11 tables)

However, in my MVC4 project VS2010 created a Membership Database with just six tables (Applications, Memberships, Profiles, Roles, Users & UsersInRoles)

How can I create a database with this (new?) schema?

like image 409
LenPopLilly Avatar asked Jan 25 '12 12:01

LenPopLilly


People also ask

How do I create an Entity Framework in Visual Studio?

Open Visual Studio and create a console project. Go to PROJECT menu -> {project name} Properties.. - and make sure that the project's target framework is . NET Framework 4.5, as shown below.

What is .netcore MVC?

The ASP.NET Core MVC framework is a lightweight, open source, highly testable presentation framework optimized for use with ASP.NET Core. ASP.NET Core MVC provides a patterns-based way to build dynamic websites that enables a clean separation of concerns.


3 Answers

All you need to do is:

change your web.config to point to the connection you would like

<add name="DefaultConnection" connectionString="uid=****;pwd=*****;server=(local);database=****" providerName="System.Data.SqlClient" />

Verify Filters\InitializeSimpleMembershipAttribute.cs

Line 41 should read:

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

Notice that autoCreateTables is set to true and the name of the connection you set in the web.config is set.

Now when a user registers it will be looking at the database you set up. If the tables don't exist yet they will be created.

like image 124
jnoreiga Avatar answered Nov 14 '22 22:11

jnoreiga


aspnet_regsql.exe is a part of ASP.Net architecture, not MVC.

My bet is that the MVC4 Developer Preview comes with some custom schema scripts in its project structure, or that it has a preview version of the new ASP.Net 4.5 version aspnet_regsql.exe installed.

If the later is true, you could perhaps use that to create a database, and tie it into your MVC3 (and prior) applications. The implications here are because of the schema differences, you would likely need to write your own Providers.

Another option would be to create the database with your MVC4 template, delete the project, and code a DA layer in your MVC3 project that uses the database. All you'd need to grab is the connection string. But again, you would have to roll your own providers as the old ones wouldn't know the new 6-table schema.

like image 32
one.beat.consumer Avatar answered Nov 14 '22 23:11

one.beat.consumer


You have to add some arguments for installing features: http://msdn.microsoft.com/en-us/library/ms229862(v=vs.80).aspx

You can run Aspnet_regsql.exe without any command-line arguments to run a wizard that will walk you through the installation.

Which tables are missing and which tables was created?

like image 26
stian.net Avatar answered Nov 14 '22 22:11

stian.net