ashes999
ashes999

Reputation: 10163

Deploying ASP.NET MVC Database to Production

How do you deploy a database when you deploy an ASP.NET MVC application to production?

I've created a standard ASP.NET MVC3 application that uses SQL Server 2008 (albeit Express) for my app. I'm using the standard forms authentication stuff that comes with ASP.NET MVC apps.

If I have to re-create my schema, for all my classes (i.e. the non aspnet_* tables), then I have SQL scripts I can run against the production DB; but what about the aspnet_* tables?

Or should I simply upload an ASP.NET MVC empty DB (~10MB) and then run my scripts against it to create my tables? Surely, there must be a better way.

(Once this is solved, I plan to use SQL scripts or DB migrations to handle changes; it's only the question of generating the initial database in production without uploading the ~10MB .MDF that I can't get around, because of the aspnet_* tables.)

Upvotes: 2

Views: 4126

Answers (3)

rycornell
rycornell

Reputation: 717

You can also deploy the db using Visual Studio.

  1. In VS, open the database explorer window
  2. Add a connection to your local db
  3. Right-click on the database and choose 'Publish to Provider'
  4. The db publishing wizard will open
  5. The wizard lets you select which db objects you want to deploy (tables, stored procedures, etc.)
  6. Select the 'Script to file' option, which will create a script that you can run on your prod db
  7. Open SQL Server Management Studio
  8. Connect to your prod db
  9. Open the script file you created with the wizard and execute the script

Upvotes: 2

Zruty
Zruty

Reputation: 8667

You could run aspnet_regsql utility on your (empty) production database to generate the aspnet_* tables. Check out the MSDN article on the utility.

Upvotes: 2

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171491

You can use aspnet_regsql.exe, located under C:\Windows\Microsoft.NET\Framework[your framework] to generate the schema in your db.

Run:

aspnet_regsql.exe /?

and you will see all of the command-line options this executable takes. -A lets you specify what features (i.e., tables) will get created. If you do not use roles, for example, you may just use -A mp.

You can choose to have it modify your database directly, or instead create a script that you can run. Some details here: http://weblogs.asp.net/lhunt/archive/2005/09/26/425966.aspx

Upvotes: 4

Related Questions