Exploring SQL ServerData Tier Applications
Bob Beauchemin
Developer Skills Partner
SQLskills
DBI309
Agenda
Data-Tier Applications
And Multi-Server Management
And SQL Azure Database
And Visual Studio/SQL Server Data Tools
Working with DACs, DACPACs, and BACPACs
Creating/Extracting and Deconstructing DACPACs
Deployment
Initial deployment
Upgrade
Import and Export - BACPAC
First, Some Terms
DAC
Encompasses all other names and concepts
DACFx
The DAC Framework, DLLs
DACPAC
The file format used by DACFx that contains the full declarative definition of a database schema. Best analogy: an MSI.
BACPAC
The file format used by DACFx to contain the definition of an application/database schema as well as its (table) data.
What Does It Do?
SQL Server Data Tools/DACFx features include:
Building a DACPAC from a set of T-SQL scripts 
Extracting a DACPAC from a database
Deploying a DACPAC to a new database
Incrementally upgrading an existing database schema via DACPAC
Exporting a BACPAC from an existing database
Importing a BACPAC to a new/empty database 
Schema comparison
Online Database Development Tools
What's The Point?
Provides services around SQL Server
Database extraction and packaging
File formats are SQL Server version-independent
DAC features enable
Managed database application lifecycle
Schema and data portability
What Problem Does It Solve?
Meant to simplify deployment across
SQL Server release/version differences
Features, T-SQL dialect
SQL Azure vs. SQL Server
T-SQL dialect, other differences
Others…
Migrating database between instances
On Prem => SQL Azure and back or between On Prem
DAC Scenarios
A Quick DAC History
DAC 1.0
SQL Server 2008 R2 Utility
VS 2010 SP1 DAC Project
DAC 1.1 – Upgrade in Place
DAC 2.0 – Object support for SQL Azure, BACPAC
DAC 3.0 
SQL Server 2012/SQL Server Data Tools
Object support for SQL Server 2005-above, SQL Azure
DACFx 3.0 in SSMS 2012
On SQL Server or SQL Azure node in Object Explorer
Databases Folder
Deploy (from DACPAC)
Import (from BACPAC)
Local file system or Windows Azure storage
Individual Databases/Tasks
Extract
Migrate Database to Azure (using BACPAC)
Export (to BACPAC)
Local file system or Windows Azure storage
Register
Upgrade
Delete (Unregister)
Consumers
DACFx 3.0 is used by
SQL Server Management Studio 2012
SQL Server Data Tools (SSDT)
SqlPackage.exe
DACFx Managed API
DACFx is also used by
SQL Azure Management Portal
SQL Azure Import/Export Service
SQL Server Utility (3.0 in SQL Server 2012)
Creating a DACPAC
From an existing database
SSMS 2008 R2 and above
Choose "Extract Data-Tier Application" from database 
Also available from SqlPackage.exe or DACFX API
DAC v3.0 support built-in to SQL Server Data Tools project
In VS 2010 Professional +/VS2012
Populate project from existing database or DACPAC file
Populate project from DDL scripts
Start from empty project
.dacpac file is build output of SSDT project
Permitted Objects
DAC 3.0 – Full SQL Server/Azure domain supported
DAC 2.0 – all SQL Azure-compatible objects supported
DAC 1.0/1.1 supports
Tables, Views, and Indexes
Multiple schemas supported
Includes constraints, collations, computed columns
Sprocs, Functions, DML Triggers (in T-SQL)
Logins (deployed to Master), Users, Roles
User-defined Table Types
Includes UDDT
Data-Tier Application Elements
Application properties (appname, version, and desc.)
Database object definitions
Instance-level object definitions (logins, collations, compatibility level)
Server-selection policy (pre-3.0)
Pre/post-deployment scripts
.dacpac is a OPC package
Contains multiple XML files
Does not contain any user data
DAC File Changes in v3.0
In DAC 2.0
BACPAC added
BACPAC is DAC files + data (compressed JSON format)
In DAC 3.0
Filenames/streams were refactored
Different XML Schema for moldel.xml and other streams
Supported Versions
SQL Server Version
DAC Feature
2000
2005
2008
2008 R2
2012
Azure
Extract DAC
No
Yes
Yes
Yes
Yes
Yes
Deploy DAC
No
SP4
SP2
Yes
Yes
Yes
Delete DAC
No
SP4
SP2
Yes
Yes
Yes
Register DAC
No
SP4
SP2
Yes
Yes
Yes
Upgrade DAC
No
SP4
SP2
Yes
Yes
No
Import BACPAC
No
SP4
SP2*
Yes*
Yes*
Yes*
Export BACPAC
No
SP4
SP2*
Yes*
Yes*
Yes*
SSMS Support
No
No
No
Yes(DAC v1)
Yes
Yes (2008 R2, 2012)
* BACPAC supported with SQL Server 2012 SSMS and SSDT
Working with DAC
SSDT Schema Compare can compare DACPACs
Compare .dacpac to another .dacpac or to existing database/database project
SSDT available as a free web download
Standalone or integrates into existing VS2010 Pro or above installation
Support for headless environment:
Install DAC tools without SSDT IDE
Install DACFramework.msi and dependencies form  SQL Server 2012 Feature Pack
Install SSDTBuildUtilities.msi for MSBuild/TeamBuild support
Working With DAC
Encapsulated in a set of libraries
Legacy utility library is Microsoft.SqlServer.Management.Dac.dll
DACFx 3.0 assembly is Microsoft.SqlServer.Dac.dll
Pre-requisites
T-SQL ScriptDom 
Microsoft SQLCLR Types
Initial Deployment
Supply name of instance for deployment
Provide a database name
Set the publish options you want
Publish DACPAC
Database and objects are created
Database options are defined by the package
Registering Data-Tier Applications
Registering a DAC requires
db_owner or better
Managing Data-Tier Applications
Entries made in msdb for installed DACs
Stored in master on SQL Azure
Must back up
Database for DAC
msdb 
Modifying database name  or deleting database will destroy association with dac history entries
No further upgrade via DAC
No utilization reports in SQL Server Utility
Upgrading Data-Tier Applications
Upgrade Data-Tier Application Wizard
Changes schema and properties of deployed applications
New database created with new schema
DAC v1.0 - Data is migrated
Original database set to read-only
Both databases then renamed
Must consider space usage
DAC V1.1+ – Upgrade in place
Alter script generated at install time
DBAs can save the script and customize
Database Drift
Detects changes to registered DAC database since last deployment/registration
Allows changes to be incorporated into a new .dacpac or dropped
SSDT Schema Compare helps merge these changes into a database of project
DACFx and SQL Azure
DACFx v3.0 supports full surface area of SQL Azure
In SQL Azure
DAC information stored in SQL Azure master database
Can Publish to SQL Azure from SSMS, SSDT or SqlPackage.exe
Used also by SQL Azure Portal
Additional DAC Operations
DAC 2.0+ can back up and move schema and data
Schema and data format known as BACPAC
Data included in compressed JSON format
DACFX exposes Import and Export methods
Accessible in PowerShell/SqlPackage.exe/API
SQL Azure portal Import/Export
Export BACPAC to local or Windows Azure Storage
Import BACPAC from local or Windows Azure Storage
SSMS 2012 can export/import database using BACPAC
DACFx v3.0
DACFX v3.0 consumed by SSDT and SSMS 2012
Target-specific model validation of database project performed at build time
SSDT supports incremental update and publish scenarios
SSDT output is v3.0 DACPAC
SqlPackage.exe - command-line tool for DAC verbs
DACFx 3.0
In DACFx 3.0
APIs updated to work with full range of DAC verbs	
Microsoft.SqlServer.Dac namespace
Primary actions contained in DacServices class (not DacStore)
Verbs to 
Create and Deploy DACPACs/BACPACs
Generate T-SQL incremental update scripts
Generate XML Drift and Deployment reports
Summary
DAC is a package format for database schema management
2.0 and above also can contain data
Used for
Managing database schema
Moving database data
Used with 
SSMS, VS, SSDT, SQL Azure Portals
Functionality depends on 
Tool version
Database version
DACPAC/BACPAC version
References
SSDT Blog - http://blogs.msdn.com/b/ssdt/
Using Data Tier Applications to Move and Manage SQL Azure Databases, SQL Server Magazine, Jan 2012
Data-tier Application 
SSDT:
http://msdn.microsoft.com/en-us/data/gg427686
SQL Server 2012 Docs
http://msdn.microsoft.com/en-us/library/ee210546
Track Resources
@sqlserver
@ms_teched
mva
Microsoft Virtual Academy

SQL Server 2012 Eval Copy
Get Certified!
Hands-On Labs
C:\Users\chrisw\Desktop\Kinect Hand.png
Resources
Connect. Share. Discuss.
ms_Learning_w.eps
Learning
Microsoft logo and tagline
Microsoft Certification & Training Resources
ms_Learning_w.eps
TechNet
Microsoft logo and tagline
Resources for IT Professionals
Resources for Developers
C:\Users\Jordan\Desktop\TechEd_2012\TechEd-logo.png
\\192.168.1.51\Shared\ADI_Projects\Microsoft\MS_11-01457_TechEd_2012_Template\Working_Art\Eval-prizes\bestbuy-gc.png
Required Slide
Complete an evaluation on CommNet and enter to win!
\\192.168.1.51\Shared\ADI_Projects\Microsoft\MS_11-01457_TechEd_2012_Template\Working_Art\Eval-prizes\Xbox360_Matte_Sensor_7-8View.png
\\192.168.1.51\Shared\ADI_Projects\Microsoft\MS_11-01457_TechEd_2012_Template\Working_Art\Eval-prizes\Geek-military-hat.jpg
\\192.168.1.51\Shared\ADI_Projects\Microsoft\MS_11-01457_TechEd_2012_Template\Working_Art\Eval-prizes\Geek-usb-hub.jpg
\\192.168.1.51\Shared\ADI_Projects\Microsoft\MS_11-01457_TechEd_2012_Template\Working_Art\Eval-prizes\LED-flashlight.jpg
\\192.168.1.51\Shared\ADI_Projects\Microsoft\MS_11-01457_TechEd_2012_Template\Working_Art\Eval-prizes\Neoprene-accessory-case.jpg
\\192.168.1.51\Shared\ADI_Projects\Microsoft\MS_11-01457_TechEd_2012_Template\Working_Art\Eval-prizes\Cloud-power-shirt.jpg
MS Tag
Scan the Tag
to evaluate this
session now on
myTechEd Mobile
\\192.168.1.51\Shared\ADI_Projects\Microsoft\MS_11-01323_SpeechTek_PPT\ADI_Art\Working_Art\Mango_Start_Phone_English_Red_061011.png
C:\Users\Jordan\Desktop\TechEd_2012\TechEd-logo.png
Microsoft logo and tagline
© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation.  Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation.  MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.