Skip to content

Instantly share code, notes, and snippets.

@mbourgon
Last active December 17, 2015 21:49
Show Gist options
  • Save mbourgon/5677862 to your computer and use it in GitHub Desktop.
Save mbourgon/5677862 to your computer and use it in GitHub Desktop.
Parse the ConnectionString information out of SSIS packages stored in MSDB on 2008/R2/2012. SSISDB will have to be handled differently.
DECLARE @DTS_Packages TABLE
(
PackageName SYSNAME,
PackageDescription SYSNAME,
Creator SYSNAME,
CreateDate DATETIME,
PackageXML XML
)
INSERT INTO @DTS_Packages
SELECT p.[name] AS [PackageName],
[description] AS [PackageDescription],
l.[name] AS [Creator],
p.[createdate],
CAST(CAST(packagedata AS VARBINARY(MAX)) AS XML) PackageXML
FROM [msdb].[dbo].[sysssispackages] p
JOIN sys.syslogins l
ON p.[ownersid] = l.[sid];
--you either need ;WITH or the previous statement needs the semicolon for the
--WITH NAMESPACE... which precludes a CTE
WITH XMLNAMESPACES ('www.microsoft.com/SqlServer/Dts' AS dts)
SELECT [@DTS_Packages].PackageName,
[@DTS_Packages].PackageDescription,
[@DTS_Packages].Creator,
[@DTS_Packages].CreateDate,
[@DTS_Packages].PackageXML,
Con.Str.value('.', 'varchar(500)') --aka give me that exact node
FROM @DTS_Packages
CROSS APPLY PackageXML.nodes('//dts:Property[@dts:Name="ConnectionString"]') AS Con(Str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment