SSIS object search using T-SQL

本文介绍如何使用SQL Server Management Studio (SSMS) 查询窗口在MSDB数据库中快速搜索已恢复的SSIS包的内容,无需使用Visual Studio BIDS会话下载包、打开包并进行代码查看。通过设置SSMS增加XML输出大小到无限,可以查看SSIS包的完整XML内容,并提供了几种搜索特定对象的方法,包括使用CONVERT()函数搜索Visual Basic 脚本、通过临时表搜索特定对象和按文件夹名称搜索对象。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

This article outlines how to quickly search for text and objects within SSIS packages that are stored in the MSDB database with the SQL Server Management Studio (SSMS) query window. In my current environment, we are commonly faced with questions regarding the content of SSIS packages that may or may not contain an object name or script. This helps us determine if the package may require to be changed. Within this article I will outline a few scenarios to quickly search the contents of any SSIS package(s) stored within the MSDB database so you do not have to use a Visual Studio BIDS session to download the package from the server, open the package, and perform the "view code" on the package, and search for a specific object name.

The first step is to setup SSMS to increase the XML output size from the default 2 MB to unlimited. This change will allow you to see complete contents of the XML data that represents the SSIS package within MSDB. Within SSMS on the menu tool bar select " Tools --> Options --> Query Results --> Results to Grid ". See the image below for the setting change for before and after.

 

XMLQASetting.JPG 

 

Below are some examples of the types of searches you can do within an SSIS package for specific objects.

Search 1: A simple SSIS package search for Visual Basic Script within the SSIS package - This is performed using the CONVERT() function in the WHERE clause to convert the "packagedata" column from the msdb.dbo.sysdtspackages90 table to a format that string matched in the where clause. This method I find quite useful for a quick search of my SSIS packages.

SELECT [name] AS SSISPackageName, CONVERT(XML, CONVERT(VARBINARY(MAX), packagedata)) AS SSISPackageXMLFROM msdb.dbo.sysdtspackages90WHERE CONVERT(VARCHAR(MAX), CONVERT(VARBINARY(MAX), packagedata)) LIKE '%sub main()%'

Search 2: SSIS Package search for a particular object using a temporary table - In the example below I use the temporary table to store the packagedata column from the msdb.dbo.sysdtspackages90 table so I can use the "SSISPackageVarchar" column to a string match for any database object that I am looking for.

SELECT {name] AS SSISPackageName, CONVERT(XML, CONVERT(VARBINARY(MAX), packagedata)) AS SSISPackageXML, CONVERT(VARCHAR(MAX), CONVERT(VARBINARY(MAX), packagedata)) AS SSISPackageVarcharINTO #SSISObjectSearchFROM msdb.dbo.sysdtspackages90SELECT *FROM #SSISObjectSearchWHERE SSISPackageVarchar LIKE '%&ltobjectName>%'

Search 3: SSIS Package search using a temporary table and a specific folder name - On our SSIS servers we use child folders beneath the default "MSDB" folder to organize our packages. In the example code below we join to the msdb.dbo.sysdtspackagefolders90 to find the folder names that are encoded in the msdb.dbo.sysdtspackages90 table. Packages that are not stored within a folder have the default value of "00000000-0000-0000-0000-000000000000" in the folderid column that is a uniqueidentifier data type withinmsdb.dbo.sysdtspackages90 table.

SELECT {name] AS SSISPackageName, CONVERT(XML, CONVERT(VARBINARY(MAX), packagedata)) AS SSISPackageXML, CONVERT(VARCHAR(MAX), CONVERT(VARBINARY(MAX), packagedata)) AS SSISPackageVarchar, SF.FolderNameINTO #SSISObjectSearchINTO ##SSISObjectSearchFROM msdb.dbo.sysdtspackages90 AS SPINNER JOIN msdb.dbo.sysdtspackagefolders90 AS SFON SF.FolderID = SP.FolderIDWHERE SF.FolderName = '<object_name>'SELECT *FROM #SSISObjectSearchWHERE SSISPackageVarchar LIKE '%&ltobjectName>%'

The result sets that are produced by the queries above will have a "SSISPackageXML" column that you can click on and open a new query analyzer window to see the complete XML of the SSIS package. From the new window you can perform a search for all the specific string occurrences or export the XML to a file name of your choosing to examine with the XML tool of your choice.

 

I hoped you enjoyed reading this article and please feel free to leave any comments/questions on the message board. Thanks for reading.

转载于:https://www.cnblogs.com/heitou/archive/2010/05/13/1734880.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值