gpt4 book ai didi

sql - 自动从 .Dtsx 文件检索版本号

转载 作者:行者123 更新时间:2023-12-02 07:51:35 25 4
gpt4 key购买 nike

有没有办法或查询可以找到 SSIS 包(*.dtsx 文件)的版本号?

我有*.dtsx我想了解的 Team Foundation Server 中的文件。

手动方式是鼠标右键点击该包,然后点击Compare查看VersionBuild但有数千个包,因此手动执行确实不可能

注意:该过程应该自动化,而不是手动

最佳答案

获取 dtsx 包中的值

  • 如果您尝试读取此包中的包版本,您可以访问 SSIS system variables 之一

    Variable        Type    Description
    -------------------------------------------
    VersionBuild Int32 The package version.
    VersionComment String Comments about the package version.
    VersionGUID String The unique identifier of the version.
    VersionMajor Int32 The major version of the package.
    VersionMinor Int32 The minor version of the package.
  • 如果您正在寻找包 SQL Server 版本,则可以在 dtsx 文件中找到它,如果您将其作为文本(或 xml)打开并搜索 PackageFormatVersion code> 属性,详细信息在以下链接中提供:

从存储在 Sql 服务器中的 .dtsx 文件中获取值

您可以点击以下链接:

它包含实现此问题的查询

从未存储在 Sql 服务器中的 .dtsx 文件中获取值

要自动读取PackageFormatVersion,您可以使用XMLParserRegex以编程方式读取它。我在 Vb.net 中编写了一段代码,该代码使用 Regex 并循环目录内的 .dtsx 文件,并获取 PackageFormatVersion 属性和找到的其他属性在 dtsx 文件头中:

  • 包文件名
  • 包格式版本
  • 创建日期
  • 创作名称
  • 创建者计算机名称
  • 创作者姓名
  • DTSID
  • 可执行类型
  • 最后修改的产品版本
  • 区域设置ID
  • 对象名称
  • 封装类型
  • 版本构建
  • 版本GUID

首先,我创建了一个名为 PackageInfo 的类,其中包含上面列出的属性

Public Class PackageInfo

Public Property PackageFileName As String
Public Property PackageFormatVersion As String
Public Property CreationDate As String
Public Property CreationName As String
Public Property CreatorComputerName As String
Public Property CreatorName As String
Public Property DTSID As String
Public Property ExecutableType As String
Public Property LastModifiedProductVersion As String
Public Property LocaleID As String
Public Property ObjectName As String
Public Property PackageType As String
Public Property VersionBuild As String
Public Property VersionGUID As String


End Class

使用正则表达式

Private Sub ReadPackagesInfo(ByVal strDirectory As String)


m_lst.Clear()

For Each strFile As String In IO.Directory.GetFiles(strDirectory, "*.dtsx", IO.SearchOption.AllDirectories)


Dim strContent As String = ""

Using sr As New IO.StreamReader(strFile)

strContent = sr.ReadToEnd
sr.Close()

End Using


Dim strPackageFormatVersion As String = Regex.Match(strContent, "(?<=""PackageFormatVersion"">)(.*)(?=</DTS:Property>)", RegexOptions.Singleline).Value
Dim strCreationDate As String = Regex.Match(strContent, "(?<=DTS:CreationDate="")(.*?)(?="")", RegexOptions.Singleline).Value
Dim strCreationName As String = Regex.Match(strContent, "(?<=DTS:CreationName="")(.*?)(?="")", RegexOptions.Singleline).Value
Dim strCreatorComputerName As String = Regex.Match(strContent, "(?<=DTS:CreatorComputerName="")(.*?)(?="")", RegexOptions.Singleline).Value
Dim strCreatorName As String = Regex.Match(strContent, "(?<=DTS:CreatorName="")(.*?)(?="")", RegexOptions.Singleline).Value
Dim strDTSID As String = Regex.Match(strContent, "(?<=DTS:DTSID="")(.*?)(?="")", RegexOptions.Singleline).Value
Dim strExecutableType As String = Regex.Match(strContent, "(?<=DTS:ExecutableType="")(.*?)(?="")", RegexOptions.Singleline).Value
Dim strLastModifiedProductVersion As String = Regex.Match(strContent, "(?<=DTS:LastModifiedProductVersion="")(.*?)(?="")", RegexOptions.Singleline).Value
Dim strLocaleID As String = Regex.Match(strContent, "(?<=DTS:LocaleID="")(.*?)(?="")", RegexOptions.Singleline).Value
Dim strObjectName As String = Regex.Match(strContent, "(?<=DTS:ObjectName="")(.*?)(?="")", RegexOptions.Singleline).Value
Dim strPackageType As String = Regex.Match(strContent, "(?<=DTS:PackageType="")(.*?)(?="")", RegexOptions.Singleline).Value
Dim strVersionBuild As String = Regex.Match(strContent, "(?<=DTS:VersionBuild="")(.*?)(?="")", RegexOptions.Singleline).Value
Dim strVersionGUID As String = Regex.Match(strContent, "(?<=DTS:VersionGUID="")(.*?)(?="")", RegexOptions.Singleline).Value



m_lst.Add(New PackageInfo With {.PackageFileName = strFile,
.PackageFormatVersion = strPackageFormatVersion,
.CreationDate = strCreationDate,
.CreationName = strCreationName,
.CreatorComputerName = strCreatorComputerName,
.CreatorName = strCreatorName,
.DTSID = strDTSID,
.ExecutableType = strExecutableType,
.LastModifiedProductVersion = strLastModifiedProductVersion,
.LocaleID = strLocaleID,
.ObjectName = strObjectName,
.PackageType = strPackageType,
.VersionBuild = strVersionBuild,
.VersionGUID = strVersionGUID})


Next



End Sub

以下代码行是从文件中读取 PackageFormatVersion 属性的代码

Dim strA As String = Regex.Match(strContent, "(?<=""PackageFormatVersion"">)(.*)(?=</DTS:Property>)", RegexOptions.Singleline).Value

使用 Xml 解析器

    Private Sub ReadPackagesInfoUsingXmlParser(ByVal strDirectory As String)

m_lst.Clear()

For Each strFile As String In IO.Directory.GetFiles(strDirectory, "*.dtsx", IO.SearchOption.AllDirectories)

Dim strPackageFormatVersion As String = ""
Dim strCreationDate As String = ""
Dim strCreationName As String = ""
Dim strCreatorComputerName As String = ""
Dim strCreatorName As String = ""
Dim strDTSID As String = ""
Dim strExecutableType As String = ""
Dim strLastModifiedProductVersion As String = ""
Dim strLocaleID As String = ""
Dim strObjectName As String = ""
Dim strPackageType As String = ""
Dim strVersionBuild As String = ""
Dim strVersionGUID As String = ""


Dim xml = XDocument.Load(strFile)

Dim ns As XNamespace = "www.microsoft.com/SqlServer/Dts"
Dim man As XmlNamespaceManager = New XmlNamespaceManager(New NameTable())
man.AddNamespace("DTS", "www.microsoft.com/SqlServer/Dts")

If Not xml.Root Is Nothing AndAlso
Not xml.Root.Descendants(ns + "Property").Attributes(ns + "Name") Is Nothing AndAlso
xml.Root.Descendants(ns + "Property").Attributes(ns + "Name").Where(Function(x) x.Value = "PackageFormatVersion").Count > 0 Then

strPackageFormatVersion = xml.Root.Descendants(ns + "Property").Attributes(ns + "Name").Where(Function(x) x.Value = "PackageFormatVersion").FirstOrDefault.Parent.Value

strCreationDate = If(xml.Root.Attributes(ns + "CreationDate").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "CreationDate").FirstOrDefault.Value)
strCreationName = If(xml.Root.Attributes(ns + "CreationName").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "CreationName").FirstOrDefault.Value)
strCreatorComputerName = If(xml.Root.Attributes(ns + "CreatorComputerName").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "CreatorComputerName").FirstOrDefault.Value)
strCreatorName = If(xml.Root.Attributes(ns + "CreatorName").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "CreatorName").FirstOrDefault.Value)
strDTSID = If(xml.Root.Attributes(ns + "DTSID").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "DTSID").FirstOrDefault.Value)
strExecutableType = If(xml.Root.Attributes(ns + "ExecutableType").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "ExecutableType").FirstOrDefault.Value)
strLastModifiedProductVersion = If(xml.Root.Attributes(ns + "LastModifiedProductVersion").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "LastModifiedProductVersion").FirstOrDefault.Value)
strLocaleID = If(xml.Root.Attributes(ns + "LocaleID").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "LocaleID").FirstOrDefault.Value)
strObjectName = If(xml.Root.Attributes(ns + "ObjectName").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "ObjectName").FirstOrDefault.Value)
strPackageType = If(xml.Root.Attributes(ns + "PackageType").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "PackageType").FirstOrDefault.Value)
strVersionBuild = If(xml.Root.Attributes(ns + "VersionBuild").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "VersionBuild").FirstOrDefault.Value)
strVersionGUID = If(xml.Root.Attributes(ns + "VersionGUID").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "VersionGUID").FirstOrDefault.Value)
End If



m_lst.Add(New PackageInfo With {.PackageFileName = strFile,
.PackageFormatVersion = strPackageFormatVersion,
.CreationDate = strCreationDate,
.CreationName = strCreationName,
.CreatorComputerName = strCreatorComputerName,
.CreatorName = strCreatorName,
.DTSID = strDTSID,
.ExecutableType = strExecutableType,
.LastModifiedProductVersion = strLastModifiedProductVersion,
.LocaleID = strLocaleID,
.ObjectName = strObjectName,
.PackageType = strPackageType,
.VersionBuild = strVersionBuild,
.VersionGUID = strVersionGUID})

Next

End Sub

演示应用

我创建了一个演示应用程序来实现此过程,您可以从以下链接下载它:

我还创建了一个新的 Git-repository对于这个演示应用程序

应用截图

enter image description here

使用 TSQL 从 .dtsx 文件获取值

您可以在 DBA.StackExchange 上阅读我的回答:

PackageFormat版本表

这是PackageFormatVersion表值

SQL Version Build # PackageFormatVersion    Visual Studio Version
2005 9 2 2005
2008 10 3 2008
2008 R2 10.5 3 2008
2012 11 6 2010 or BI 2012
2014 12 8 2012 CTP2 or 2013
2016 13 8 2015

关于sql - 自动从 .Dtsx 文件检索版本号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43591672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com