LenPopLilly
LenPopLilly

Reputation: 1227

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?

Upvotes: 7

Views: 15083

Answers (3)

jnoreiga
jnoreiga

Reputation: 2175

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.

Upvotes: 4

one.beat.consumer
one.beat.consumer

Reputation: 9504

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.

Upvotes: 2

stian.net
stian.net

Reputation: 3963

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?

Upvotes: 2

Related Questions