Technical Article

Changing the Owner of a Single DTS Package

,

This is not an original script - but one I modified from an article by Darren Green on databasejournal.com (02/21/2000).  His original script changed the owner of all DTS packages owned by @old_owner to be owned by @new_owner. 

This script will change the owner of the most recent version of a specific DTS package (@p_name) to be owned by @new_owner.

The stored procedure should be placed in the msdb database and executed from that database.  Example command is:

EXEC sp_DTSReplaceOwner
@p_name = 'package name',
@new_owner = 'MyDomain\OwnerName'

CREATE  PROCEDURE sp_DTSReplaceOwner
 @p_name sysname,
 @new_owner sysname
AS

DECLARE @name sysname, @id uniqueidentifier
DECLARE cur_sysdtspackages CURSOR FOR 
   
SELECT     DISTINCT [name],[id]
FROM         sysdtspackages
WHERE     (createdate =
            (SELECT     TOP 1 createdate
             FROM          sysdtspackages
             WHERE      (name = @p_name)
             ORDER BY createdate DESC))
 AND (name = @p_name)

 OPEN cur_sysdtspackages
 
 FETCH NEXT FROM cur_sysdtspackages
 INTO @name, @id
  
 WHILE @@FETCH_STATUS = 0
 BEGIN
     EXEC sp_reassign_dtspackageowner @name=@name, @id=@id, @newloginname=@new_owner

     FETCH NEXT FROM cur_sysdtspackages
     INTO @name, @id
 END

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating