Deploying ASP.NET MVC Database to Production - asp.net-mvc

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.)

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

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

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

Related

Change servers (Dev, UAT, Prod) for Entity Framework

My application is developed in ASP.NET MVC with Entity Framework (using a database-first approach). Currently, this entity is pointing to the dev database server. I want to change it to an UAT server for testing and finally production server for deployment.
My question is, is it achievable only by creating a different .edmx file for each of the servers always and rebuild it? Or is there an easy way to change it other than creating a new connection (.edmx file) every time?
Thanks

Creating Database Project from Database in Azure

Here are the steps I took:
In Visual Studio, I created an ASP.NET MVC application with authentication
I specified that the database is an Azure SQL Database living in the cloud
So at this point I have a single project in my solution, the web application project for ASP.NET. And I have this database created in Azure with my membership database objects.
Now what I want to do is create a database project in this same solution for more detailed and in depth database development.
I created a database project, and I can easily set to deploy to Azure but I would be "overwriting" the Azure database that was created initially.
How can I "refresh" the database project I just created to reflect the existing database in Azure at this point so I'm not overwriting?
Basically I'm looking to "sync" up the existing Azure SQL Database with the new database project I just created in the solution.
Any way to do this?
Thanks in advance!
Basically what you want is the Schema Compare feature from SSDT (Sql Server data tools)
https://msdn.microsoft.com/en-us/library/hh272690(v=vs.103).aspx

entity framework db first

I have built my MVC 5 project based on entity framework Database First approach by following video tutorials. But what I have obtained is the model. There is nothing in the app_data folder. I want to obtain the .mdf file as well so that I can deploy the database to the azure.
Note: I'm using the server explorer database in VS2013.
I dont think you will be getting any .mdf files on app_data folder.
To deploy your database to Azure:
Right click your database on SQL server, then Tasks->Generate Scripts. On scripting options, select sql azure server
Login to your azure account and create a SQL server and run generated script from the portal by clicking the link below:
while creating your EF connection, use the connection string for your Azure Database like:
At the end you should be ready to use your ORM.

How to go about deployment of ASP.Net 4.5 / MVC 4 /SQL Express 2008 R2 to a Windows Azure Free Website

I am very new to Windows Azure - have been into asp.net for about 10 years now and have been deploying applications via Database backup and restore on production and copy of final code bits from source control to the root folder on production database.
I am doing my initial reading and finding it a bit difficult to absorb the overall process of deploying an ASP.Net MVC web Application to Azure.
I have managed to have the database and the website code on Azure and it is up and running, but I can't get to terms on the following points and want to understand them better to have a regular deployment on place as versions of my app keep going up.
Database doesn't work like backup a local database and then upload .bak file and restore to the production server.
Nor can I see my website files.
Update: 04-Aug-2013
Azure Websites have an FTP option. You can see your FTP host name in respective website Dashboard. The username and password for FTP are located in the publish settings file (note: you got to pick up the FTP username and password, NOT the publish username/password. They both are different.
When I am getting ready for version 2.0 of my product, how do I get the database from the Azure SQL, upgrade it to 2.0 and put it back?
I assume the publishing wizard from Visual Studio should be able to take care of code upgrade, but how do I edit my production web.config file on the fly?
How do I take my website offline and show users my custom "offline" page when I am in the middle of the upgrade? (Stopping the website shows up the Windows Azure site not available page).
For your database backup / upgrade questions
For migration of databases to SQL Azure (or pulling them down) the SQL Database Migration Wizard has proven to be a lifesaver for me, get it here:
http://sqlazuremw.codeplex.com/
This will pull and push both data and schema for your database.
For seeing your website files
You won't be able to if you are using Windows Azure Websites.
For editing web.config on fly
You can't. BUT -- you can edit connection strings and appsettings through the 'configure' tab of your website like so:
Turning your website offline during upgrade
While you cannot specifically use the app_offline route without another deployment. One thing you could do is change your default document. This is easily done right in the same 'configure' tab for the website in the portal as I mentioned above, see here:
Hope this helps.

How to add existing SQL Server database to app_data folder of asp.net MVC project

I have an existing database in SQL Server. I am trying to create an asp.net mvc project around this db.
For this purpose I need to add the db to app_data folder of asp.net MVC project
How do I achieve this?
Note:
The SQL Server is in another system and I do not have rights to install SQL Server Express on my machine as well :(
You don't need to add app_data directory or install SQL Express on your machine. All you need is a connection string allowing you to connect to the remote database.
Data Source=NameOfDbServer;Database=DatabaseName;User ID=User;Password=PWD;Trusted_Connection=False
Once you have the connection string you can start querying the database. The way you do this will depend primary on the technology you would like to use: NHibernate, LINQ to SQL, LINQ To Entities, plain old ADO.NET, ...

Resources