本文介绍了如何找到SQL Server数据层应用程序的当前版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用SQL Server数据层应用程序(dacpac或DAC包),我很难找到数据库的当前版本.

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. 在SQL Server Management Studio中
  2. 通过SQL语句
  3. 以编程方式使用.NET代码

推荐答案

在SQL Server Management Studio中

来自 http://msdn.microsoft.com/zh- us/library/ee210574.aspx

要查看部署到数据库引擎实例的DAC的详细信息,请执行以下操作:

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

  1. 选择视图/对象资源管理器菜单.

对象资源管理器窗格连接到的实例.

选择查看/对象资源管理器"的详细信息菜单.

对象资源管理器中选择映射到实例的服务器节点,然后导航到 Management \ Data-tier Applications 节点.

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

详细信息页面顶部窗格中的列表视图列出了部署到数据库引擎实例的每个DAC.选择一个DAC以在页面底部的详细信息窗格中显示信息.

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.

数据层应用程序"节点的右键单击菜单还用于部署新的DAC或删除现有的DAC.

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

SELECT instance_name, type_version FROM msdb.dbo.sysdac_instances

通过Azure上的SQL语句

SELECT instance_name, type_version FROM master.dbo.sysdac_instances

以编程方式使用.NET代码

请注意,在DacFx 3.0中,这不再有效.查看我的其他答案以了解解决方法.

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.

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)

这篇关于如何找到SQL Server数据层应用程序的当前版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 15:35