How to move EF migration and update database in Azure SQL DB - sql

I have an Entity framework project created in Visual Studio 2019.
I have created a migration using Add-migration, and have updated the local SQL DB using Update-database. The changes in migration are reflected in (localdb)\MSSQLLocalDB. Everything is working as it should.
Now I want to publish my application from VS, and want the changes in my migration and local DB to move/migrate to the Azure SQL DB for use by masses.
How do I make sure after publishing, the changes have migrated to the Azure SQL DB?
Thanks,
KB

If you have access to azure database from your local just do Update-Database with azure database connection string. otherwise, you should do this somewhere in your application:
yourDbContext.Database.Migrate();

Related

offline DMS migration from Azure SQL VM to Azure SQL DB

I am migrating my databases from Azure SQL VM to Azure SQL DB using offline migration but while migrating I am getting a error i.e " Microsoft.Azure.Management.DataMigration.Models.ODataError"
I am using powershell script to migrate the database.
I don't know what is wrong in this and why am getting this error.
I have attached the error screenshot herein.
As per this thread on Microsoft Q&A, the issue could be in relation to different collation on the source and destination DB's. I recommend you to raise a support ticket if possible.
Alternatively, you can use SQL Server Management Studio(SSMS) to migrate the Database.
Install the SSMS in your local machine and connect to the Azure SQL VM by following connect to SQL server steps in the tutorial.
Once you are connected with the server, follow the steps as mentioned in this thread to migrate the database to Azure SQL Database.

How do I extract a database schema from a dacpac file?

I was doing a project a few months back using Azure's free trial and my trial ran out.
I was using a database engine server on SQL Server Management Studio and now I can't access the server anymore.
I have a dacpac file though that contains the schema structure of the database of the project I was working on.
How do I create a new database from my dacpac file in Microsoft SQL Server Management Studio?
From Sql Server Management Studio, use the Deploy Data-tier Application menu item to open a deployment wizard.
As joshb said, you can use Deploy a Data-tier Application.
Deploy a data-tier application (DAC) from a DAC package to an existing instance of the database engine or Azure SQL Database using a wizard or a PowerShell script.
The deployment process registers a DAC instance by storing the DAC definition in the msdb system database (master in SQL Database); creates a database, then populates that database with all the database objects defined in the DAC.
How do I create a new database from my dacpac file in Microsoft SQL Server Management Studio?
You can reference my steps:
For example, I have a dacpac file:
Using Deploy a data-tier application:
Select packages:
Update configuration:
Depoly DAC and finished:
The new database is created successfully:
Hope this helps.

Is it possible to restore a SQL Server database in Azure?

I have a backup of a SQL Server 2008 database. I'd like to restore it as an Azure SQL Server database. Is this possible?
P.S. I've seen a couple of questions to this effect from 2014. Is it possible today?
AFAIK, no it's not possible.
The Unsupported in SQL Azure doco https://azure.microsoft.com/en-us/documentation/articles/sql-database-transact-sql-information/ directs you to BOL and RESTORE shows it's not available in SQL Azure.
https://msdn.microsoft.com/en-us/library/ms186858.aspx
Are you able to restore the backup to an instance of SQL 2008 on-premises/locally first? If so you can then use management studio to Export the data and schema as a BACPAC or DACPAC file (export data tier application), which can then be imported into an Azure database using the Import data tier application. You can also use the Taks -> Generate Scripts option from the database node in the management studio, ensure you check on include schema and data - then the SQL files can be executed against your SQL Azure instance as well.
There are some features which aren't available in SQL Azure that are on the server product, but the import will tell you about those if there are any - things like FILESTREAM aren't supported in Azure. Here is the link to take you through steps to migrate from SQL server to SQL Azure - and here are the differences in supported features between the two.
I have some production databases in Azure and frequently download them as data tier apps, import them into a local instance of SQL Server to do some debugging or testing, its a painless process.

Issue deploying SQL Server database from local machine to SQL Azure

I have a database I've created on my local machine that I can't seem to correctly deploy to SQL Azure. I'm deploying two databases, including the one that provides user membership.
Every time I attempt this, when I try to login and access to the database is attempted, I receive a The system cannot find the file specified error:
I've tried deploying the database every way I could from Microsoft SQL Management Studio - by right clicking my databases and "Deploy Database to SQL Azure", by generating drop and create data only SQL scripts and running these against an existing target database, by creating a bacpac and importing this and all of these have the same result.
I've double checked connection strings in my .NET MVC applications web.config and these are all correct.
Interestingly, if I run my website locally with connection strings that pointed to my updated Azure SQL db, everything works fine - but on my Azure Website I always get the same results.
Your issue actually looks like a connection string issue but if anyone else ends up here thanks to Google you can resolve orphaned users on Azure SQL Db using:
ALTER USER <user_name> WITH Login = <login_name>;
I am not a AZURE expert, but when moving DB's from one server to another sometimes user's get orphaned making the DB not accessible.
Can you run this command on the AZURE DB via SQL MANAGEMENT STUDIO?
exec sp_change_users_login 'Report'
It will tell you what username and UserSSID may be orphaned. If indeed there is a returned record run
EXEC sp_change_users_login 'Auto_Fix', '[[UserName_goes_here]]'

Visual Studio database project won't deploy to SQL Azure

I've ran into problem very similar to this. I have a .dbproj Visual Studio database project. It deploys just fine in SQL Server Express. Now I want to deploy it to SQL Azure - I change the connection parameters but deployment fails with the following text:
C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.TSqlTasks.targets(120,5): Error Deploy01234: The target database schema provider could not be determined. Deployment cannot continue.
Done executing task "SqlDeployTask" -- FAILED.
Is deploying .dbproj projects to SQL Azure supported? How do I make Visual Studio deploy the database into SQL Azure? What are other ways to achieve more or less the same results except recreating the database manually using Azure portal?
If you are using Visual Studio 2012, you can now create a Database project and go to Properties - set its Target Platform to SQL Azure in Project Settings tab. Also you can configure the setting for dacpac output. Use this file to import directly as a new SQL Azure database.
As far as I know, Database projects are still not supported by Windows Azure. You can deploy the project to a local SQL server and then use the "Generate Scripts" feature to port the database to SQL Azure. See this link.
An easy solution is to create the database locally and use the SQL Azure Migration Wizard to do the migration up to SQL Azure. It works very well in just a few clicks (and will fix common errors).
Database projects don't work with SQL Azure. What I do is before deploying, create a brand new database on local server (to ensure it is up to date with no dev scripts), and then sync that database to Azure with RedGate SQL Compare. I do a backup first with RedGate SQL Azure Backup.
When we first built DB projects, SQLAzure was still going through its identity crisis and didn't know what it wanted to be. ;)
DBProjects support a significant superset of capabilities vs. SQLAzure. Therefore, it's quite possible that it'll create scripts that won't run against SQLAzure.
I know that the team who took-over the DBProject tooling were looking at restricting the database project generators to output SQLAzure-compatible scripts, but I don't know how far they got or whether they decided to proceed.
I echo dunnry's suggestion above and use the SQL Azure Migration Wizard or Jeremy's and use SQL 2008 R2 and generate Azure-compatible scripts.