sql-server-2008-r2data-tier-applications

How do I find the current version of a SQL Server data-tier application?


We are using a SQL Server Data-tier application (dacpac or DAC pack) and I'm having a hard time finding the current version of the database.

Is there a way to obtain the current version using any of these methods:

  1. From within SQL Server Management Studio
  2. Via a SQL statement
  3. Programmatically using .NET code

Solution

  • From within SQL Server Management Studio

    From http://msdn.microsoft.com/en-us/library/ee210574.aspx

    To view the details of a DAC deployed to an instance of the Database Engine:

    1. Select the View/Object Explorer menu.

    2. Connect to the instance of the from the Object Explorer pane.

    3. Select the View/Object Explorer Details menu.

    4. Select the server node in Object Explorer that maps to the instance, and then navigate to the Management\Data-tier Applications node.

    5. The list view in the top pane of the details page lists each DAC deployed to the instance of the Database Engine. Select a DAC to display the information in the detail pane at the bottom of the page.

    The right-click menu of the Data-tier Applications node is also used to deploy a new DAC or delete an existing DAC.

    Via a SQL statement

    SELECT instance_name, type_version FROM msdb.dbo.sysdac_instances
    

    Via a SQL statement on Azure

    SELECT instance_name, type_version FROM master.dbo.sysdac_instances
    

    Programmatically using .NET code

    Note that in DacFx 3.0 this is no longer valid. See my other answer for a way to do it.

    C#

    ServerConnection serverConnection;
    string databaseName;
    
    // Establish a connection to the SQL Server instance.
    using (SqlConnection sqlConnection =
        new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
    {
        serverConnection = new ServerConnection(sqlConnection);
        serverConnection.Connect();
    
        // Assumes default database in connection string is the database we are trying to query.
        databaseName = sqlConnection.Database;
    }
    
    // Get the DAC info.
    DacStore dacstore = new DacStore(serverConnection);
    var dacInstance = dacstore.DacInstances[databaseName];
    System.Diagnostics.Debug.Print("Database {0} has Dac pack version {1}.", databaseName, dacInstance.Type.Version);
    

    VB.NET

    Dim serverConnection As ServerConnection
    Dim databaseName As String
    
    ' Establish a connection to the SQL Server instance.
    Using sqlConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString)
        serverConnection = New ServerConnection(sqlConnection)
        serverConnection.Connect()
    
        ' Assumes default database in connection string is the database we are trying to query.
        databaseName = sqlConnection.Database
    End Using
    
    ' Get the DAC info.
    Dim dacstore As New DacStore(serverConnection)
    Dim dacInstance = dacstore.DacInstances(databaseName)
    System.Diagnostics.Debug.Print("Database {0} has Dac pack version {1}.", databaseName, dacInstance.Type.Version)