Deploy a Database By Using a DAC
Use the Deploy a Database to SQL Azure Wizard to deploy a database between an instance of the Database Engine and a Azure SQL Database server, or between two Azure SQL Databaseservers.
Before You Begin
The wizard uses a Data-tier Application (DAC) BACPAC archive file to deploy both the data and the definitions of database objects. It performs a DAC export operation from the source database, and a DAC import to the destination.
Database Options and Settings
By default, the database created during the deployment will have the default settings from the CREATE DATABASE statement. The exception is that the database collation and compatibility level are set to the values from the source database.
Database options, such as TRUSTWORTHY, DB_CHAINING and HONOR_BROKER_PRIORITY, cannot be adjusted as part of the deployment process. Physical properties, such as the number of filegroups, or the numbers and sizes of files cannot be altered as part of the deployment process. After the deployment completes, you can use the ALTER DATABASE statement, SQL Server Management Studio, or SQL Server PowerShell to tailor the database.
Limitations and Restrictions
The Deploy Database wizard supports deploying a database:
From an instance of the Database Engine to Azure SQL Database.
From Azure SQL Database to an instance of the Database Engine.
Between two Azure SQL Database servers.
The wizard does not support deploying databases between two instances of the Database Engine.
An instance of the Database Engine must be running SQL Server 2005 Service Pack 4 (SP4) or later to work with the wizard. If a database on an instance of the Database Engine contains objects not supported on Azure SQL Database, you cannot use the wizard to deploy the database to Azure SQL Database. If a database on Azure SQL Database contains objects not supported by SQL Server, you cannot use the wizard to deploy the database to instances of SQL Server.
To improve security, SQL Server Authentication logins are stored in a DAC BACPAC file without a password. When the BACPAC is imported, the login is created as a disabled login with a generated password. To enable the logins, log in using a login that has ALTER ANY LOGIN permission and use ALTER LOGIN to enable the login and assign a new password that can be communicated to the user. This is not needed for Windows Authentication logins because their passwords are not managed by SQL Server.
The wizard requires DAC export permissions on the source database. The login requires at least ALTER ANY LOGIN and database scope VIEW DEFINITION permissions, as well as SELECT permissions on sys.sql_expression_dependencies. Exporting a DAC can be done by members of the securityadmin fixed server role who are also members of the database_owner fixed database role in the database from which the DAC is exported. Members of the sysadmin fixed server role or the built-in SQL Server system administrator account named sa can also export a DAC.
The wizard requires DAC import permissions on the destination instance or server. The login must be a member of the sysadmin or serveradmin fixed server roles, or in the dbcreator fixed server role and have ALTER ANY LOGIN permissions. The built-in SQL Server system administrator account named sa can also import a DAC. Importing a DAC with logins to SQL Database requires membership in the loginmanager or serveradmin roles. Importing a DAC without logins to SQL Database requires membership in the dbmanager or serveradmin roles.
Using the Deploy Database Wizard
To migrate a database using the Deploy Database Wizard
Connect to the location of the database you want to deploy. You can specify either an instance of Database Engine or a Azure SQL Database server.
In Object Explorer, expand the node for the instance that has the database.
Expand the Databases node.
Right click the database you want to deploy, select Tasks, and then select Deploy Database to SQL Azure…
Complete the Wizard dialogs:
This page describes the steps for the Deploy Database Wizard.
Do not show this page again. - Click the check box to stop the Introduction page from being displayed in the future.
Next - Proceeds to the Deployment Settings page.
Cancel – Cancels the operation and closes the Wizard.
Deployment Settings Page
Use this page to specify the destination server and to provide details about your new database.
Server connection – Specify server connection details and then click Connect to verify the connection.
New database name – Specify a name for the new database.
SQL Database database settings:
SQL Database edition – Select the edition of SQL Database from the drop-down menu.
Maximum database size – Select the maximum database size from the drop-down menu.
Specify a local directory for the temporary file, which is the BACPAC archive file. Note that the file will be created at the specified location and will remain there after the operation completes.
Use this page to review the specified source and target settings for the operation. To complete the deploy operation using the specified settings, click Finish. To cancel the deploy operation and exit the Wizard, click Cancel.
This page displays a progress bar that indicates the status of the operation. To view detailed status, click the View details option.
This page reports the success or failure of the deploy operation, showing the results of each action. Any action that encountered an error will have a link in the Result column. Click the link to view a report of the error for that action.
Click Finish to close the Wizard.
Using a .Net Framework Application
To deploy a database using the DacStoreExport() and Import() methods in a .Net Framework application.
To view a code example, download the DAC sample application on Codeplex
Create a SMO Server object and set it to the instance or server that contains the database to be deployed.
Open a ServerConnection object and connect to the same instance.
Use the Export method of the Microsoft.SqlServer.Management.Dac.DacStore type to export the database to a BACPAC file. Specify the name of the database to be exported, and the path to the folder where the BACPAC file is to be placed.
Create a SMO Server object and set it to the destination instance or server.
Open a ServerConnection object and connect to the same instance.
Use the Import method of the Microsoft.SqlServer.Management.Dac.DacStore type to import the BACPAC. Specify the BACPAC file created by the export.