How to create/open DAC application in Visual Studio 2012?

23k views Asked by At

I am having a hard time figuring how to actually create or even open a DAC application with Visual Studio 2012. I am using SQL Server 2012. I have SSDT installed.

Creating from Visual Studio:

According to online documentation I should be able to see a project template with the name "Data Tier Application" but all I see is SQL Server Database Project. Are they the same?

Creating from SSMS:

In an online video the presenter is using SSMS -> Database -> Right Click -> Create Project menu item, and after the wizard a VS project is popped open. I do not have this menu item, what I have is Tasks -> Export as Data Tier Application. This creates the DACPAC file but not the VS project, and I could not figure out how to open a dacpac from VS.

1

There are 1 answers

3
Kevin Cunnane On BEST ANSWER

The purpose of a DACPAC is to provide a portable representation of a database schema, that can be used to deploy that schema to a database, import it into a database project in Visual Studio, and be used in functions like Schema Compare to examine differences between different sources. Whenever you build a database project in Visual Studio a .dacpac file will be generated, and this can then be used to deploy the schema defined in that project to a database.

The best place for full information is the SSDT help, but I'll give you a quick summary.

If you already have a DACPAC, you can use it in VS in the following ways:

  • Import the schema into a project by right-clicking on the project in Solution Explorer and choosing "Import -> Data-tier Application (*.dacpac)". Then choose your dacpac, and the contents will be converted into SQL Scripts and added to the project
  • Publish the dacpac to a database by opening SQL Server Object Explorer, navigating to a server, right-clicking on Databases and choosing "Publish Data-tier Application..." This will publish the contents of a DACPAC up to a database on that server. You could update a database by right-clicking on a database in the Databases list. Note that if the SQL Server Object Explorer view isn't open, you can select "View -> SQL Server Object Explorer" to ensure it appears.

To create a DACPAC in Visual Studio, you can

  • Build a project. This creates a dacpac in the bin\Debug directory (assuming you build in Debug mode).
  • Snapshot a project. This creates a dacpac and saves it in the project. It's very useful to track point in time versions of your database schema and compare previous versions of the database to the latest definitions.
  • Right-click on a database in SQL Server Object Explorer and choose "Extract Data-tier Application..." This will create a dacpac that represents the database contents.

Finally I'm not sure what video you viewed, but it's possible they showed right-clicking on a DB in SQL Server Object Explorer and creating a project from there. That's a very common way to start development using a database project, since often you'll already have a database containing your schema. Generally the best practices would be to develop using a project, and use dacpacs (and possibly command line deployment tools like SqlPackage.exe) when deploying out to different environments such as your production servers (again dacpacs are great for transporting schema definitions and deploying them to different environments). Hope this helps answer your question!