Creating Database Project from Database in Azure - asp.net-mvc

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

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

How to publish to azure

I have an mvc application thats built using the repository pattern. My Database resides in the SmokersTavern.Data folder. I have published the site to azure. On startup the user must logon thereof will be redirected to the Products table. However I get the following error.
It is not allowed to connect to local database when your web app has been published to Azure.
You should create an Azure sql database and connect to it instead. Here's the tutorial for you to refer.
You need to create an Azure resource group deployment project with your Visual Studio web application so that Visual Studio knows where to publish your code. Please take a look at this:
Creating and deploying Azure resource groups through Visual Studio
Although, you are using the 'Publish to Azure' feature, I don't see the resource group configuration in the Solution Explorer pane on the right (based upon the screen capture you provided).
Following this document will walk you through the set-up, configuration, and publishing of your web application to Azure.
I created the app service + sql and in my visual studio I connected to app service created on Azure. My connection string in my config file was not that of the Azure sql db

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.

AspNet Identity Framework writing to master database on SQL Azure

I'm running into an issue when trying to deploy a simple MVC website to Azure. I am using 1 azure website and 1 Azure SQL database.
The boilerplate MVC template in VS2013 uses the Microsoft.AspNet.Identity.EntityFramework provider for the AccountController.cs default controller. When I use this to create the database locally, everything works just fine. However, when I deploy to Azure Websites and update the connection string, the site throws this error:
Cannot open database "master" requested by the login. The login failed.
Login failed for user 'vanillawebsite'.
See full stack trace here: http://pastebin.com/r9jvXgyW (it's massive)
Obviously, on SQL Azure there's no master database, so the default implementation of AspNet Identity Eneity Framework seems to need it though. Manually scripting out the schema to the database doesn't help either (it still attempts to access master for some reason)
Why is it trying to access master database, and how can I work around this?
As said before, SQL Azure has master database and usually when you see this message means that SQL user used in connection string does not have a right to access to the DB in question. Or the DB does not exist, i.e. misspelled name.

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

Resources