AlanS
Starting Member
28 Posts |
Posted - 2007-10-05 : 12:21:48
|
I've developed several hundred lines of T-SQL to extract all the text from the stored procedures, UDFs and DTS packages on any given instance of SQL Server. I'm having a problem with a part of the process (shown in CODE SECTION A, below), which is designed to (a) get a list of all DTS packages, (b) for each package in the list create a new package object (first "EXEC @rc" statement), (c) load the package from SQL Server into the newly created package object (second "EXEC @rc" statement), and (d) pass the package's object token and name to the _SearchProcessDTS stored procedure, which extracts all the text from the package's various collections.This code runs flawlessly against my local instance of SQL Server, correctly and accurately extracting all the desired information. When I run it against a remote instance (installed on another machine on our network), step (c) consistently fails for every DTS package. The error reporting routines (shown in CODE SECTION B, below) always show an error code of -2147024888 (0x80070008), and that the stored procedure sp_OAGetErrorInfo itself fails when trying to obtain the usual information on that error code. I am using Windows authentication, and am assigned to the System Administrators server role on the remote instance of SQL Server.One other quirk here is that yesterday, while experimenting with enlarging the size of certain variables and table fields, this code worked ONCE against the remote server. Since then, however, it has reverted to the error status described above, even though I've left those sizes at their increased values (and they appear to have no connection with the code shown here).What am I doing wrong?-- CODE SECTION A:-- DECLARE variablesDECLARE @DTSPackages TABLE (PackageName varchar(1000))DECLARE @CurrentPkg varchar(1000)DECLARE @rc intDECLARE @ObjectToken intDECLARE @location varchar(100)DECLARE @SvrName varchar(1000)-- populate @DTSPackages tableINSERT INTO @DTSPackages (PackageName)SELECT [name] FROM msdb..sysdtspackagesWHERE [name] LIKE dbo._GetSearchConfig('DTSPackageMask')-- process DTS packagesSET @SvrName = CAST(SERVERPROPERTY('ServerName') AS varchar)PRINT '** Server Name: ' + @SvrNameWHILE (SELECT COUNT(*) FROM @DTSPackages) > 0BEGIN SET @CurrentPkg = (SELECT TOP 1 PackageName FROM @DTSPackages ORDER BY PackageName) DELETE FROM @DTSPackages WHERE PackageName = @CurrentPkg SET @location = '_SearchPopulate:1:DTS Packages:' + @CurrentPkg EXEC @rc = sp_OACreate 'DTS.Package', @ObjectToken OUTPUT IF @rc <> 0 EXEC sp_displayoaerrorinfo @ObjectToken, @rc, @location SET @location = '_SearchPopulate:2:DTS Packages:' + @CurrentPkg EXEC @rc = sp_OAMethod @ObjectToken, 'LoadFromSQLServer', NULL, @SvrName, '', '', '256', '', '', '', @CurrentPkg IF @rc <> 0 EXEC sp_displayoaerrorinfo @ObjectToken, @rc, @location PRINT '** DTS Package: ' + @CurrentPkg EXEC _SearchProcessDTS @ObjectToken, @CurrentPkgEND-- CODE SECTION B:-- CREATE sp_hexadecimal stored procedureIF EXISTS (SELECT [id] FROM sysobjects WHERE ([name] = 'sp_hexadecimal') AND (xtype = 'P')) DROP PROCEDURE sp_hexadecimalGOCREATE PROCEDURE sp_hexadecimal @binvalue varbinary(255), @hexvalue varchar(255) OUTPUTASDECLARE @charvalue varchar(255)DECLARE @i intDECLARE @length intDECLARE @hexstring char(16)SELECT @charvalue = '0x'SELECT @i = 1SELECT @length = DATALENGTH(@binvalue)SELECT @hexstring = '0123456789abcdef'WHILE (@i <= @length)BEGINDECLARE @tempint intDECLARE @firstint intDECLARE @secondint intSELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))SELECT @firstint = FLOOR(@tempint/16)SELECT @secondint = @tempint - (@firstint*16)SELECT @charvalue = @charvalue +SUBSTRING(@hexstring, @firstint+1, 1) +SUBSTRING(@hexstring, @secondint+1, 1)SELECT @i = @i + 1ENDSELECT @hexvalue = @charvalueGO-- CREATE sp_displayoaerrorinfo stored procedureIF EXISTS (SELECT [id] FROM sysobjects WHERE ([name] = 'sp_displayoaerrorinfo') AND (xtype = 'P')) DROP PROCEDURE sp_displayoaerrorinfoGOCREATE PROCEDURE sp_displayoaerrorinfo @object int, @hresult int, @locationcode varchar(100) = nullASDECLARE @output varchar(255)DECLARE @hrhex char(10)DECLARE @hr intDECLARE @source varchar(255)DECLARE @description varchar(255)DECLARE @hrhex2 char(10)--PRINT 'OLE Automation Error Information'EXEC sp_hexadecimal @hresult, @hrhex OUT--SELECT @output = ' HRESULT: ' + @hrhex--PRINT @outputEXEC @hr = sp_OAGetErrorInfo @object, @source OUT, @description OUTIF @hr = 0BEGIN--SELECT @output = ' Source: ' + @source--PRINT @output--SELECT @output = ' Description: ' + @description--PRINT @outputPRINT '[' + ISNULL(@locationcode, '#') + '] OLE Automation Error; Code: ' + CAST(@hresult AS varchar) + ' (' + @hrhex + '); Src: ' + @source + '; Desc: ' + @descriptionENDELSEBEGIN --PRINT ' sp_OAGetErrorInfo failed.' EXEC sp_hexadecimal @hr, @hrhex2 OUT PRINT '[' + ISNULL(@locationcode, '#') + '] sp_OAGetErrorInfo failed with error code ' + CAST(@hr AS varchar) + ' (' + @hrhex2 + ') on call for error code ' + CAST(@hresult AS varchar) + ' (' + @hrhex + ')' RETURNENDGO |
|