En seguida el código de un SP que ejecuta paquetes DTS en SQL 2000.
1: CREATE PROCEDURE [dbo].[spExecuteDTSPackage]
2: @in_varPackageName Varchar(100),
3: @in_varServerName varchar(20),
4: @out_chrErrorType Char(3) = 'SYS' OUTPUT,
5: @out_intErrorCode Int =0 OUTPUT
6: AS
7: DECLARE @object int,
8: @hr int,
9: @src varchar(255),
10: @desc varchar(255),
11: @val as varchar(100),@err int,@errDesc varchar(500)
12:
13:
14: -- LOAD A VARIABLE WITH A NEEDED PROCEDURE CALL..
15: SELECT @val = 'LoadFromSQLServer(' + @in_varServerName + ', "", "", 256, , , , ' + @in_varPackageName + ')';
16: -- CREATE THE OBJECT.
17: EXEC @hr = master..sp_OACreate 'DTS.package', @object OUT;
18: IF @hr <> 0
19: BEGIN
20: -- Trapping error if object not created
21: EXEC master..sp_OAGetErrorInfo @object, @src OUT, @desc OUT
22: SELECT @err=@@error
23: SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
24: if @err<>0
25: goto Catch
26: END
27: -- GET THE DTS PACKAGE REFRENCE.
28:
29: EXEC @hr = master..sp_OAMethod @object, @Val, NULL;
30: IF @hr <> 0
31: BEGIN
32: -- Trapping error if Execute failed
33: EXEC master..sp_OAGetErrorInfo @object, @src OUT, @desc OUT
34: SELECT @err=@@error
35: SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
36: if @err<>0
37: goto Catch
38: END
39:
40: -- EXECUTE THE DTS PACKAGE.
41: EXEC @hr = master..sp_OAMethod @object, 'Execute'
42: IF @hr <> 0
43: BEGIN
44: -- Trapping error if Execute failed
45: EXEC master..sp_OAGetErrorInfo @object, @src OUT, @desc OUT
46: SELECT @err=@@error
47: SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
48: if @err<>0
49: goto Catch
50: END
51:
52: goto End
53:
54:
55: Catch:
56:
57: SELECT @errDesc=Description from master..sysmessages WHERE error=@err
58: RAISERROR (@errDesc,16,1)
59: return @err
60:
61: End:
62:
63: return 0
64: GO
2: @in_varPackageName Varchar(100),
3: @in_varServerName varchar(20),
4: @out_chrErrorType Char(3) = 'SYS' OUTPUT,
5: @out_intErrorCode Int =0 OUTPUT
6: AS
7: DECLARE @object int,
8: @hr int,
9: @src varchar(255),
10: @desc varchar(255),
11: @val as varchar(100),@err int,@errDesc varchar(500)
12:
13:
14: -- LOAD A VARIABLE WITH A NEEDED PROCEDURE CALL..
15: SELECT @val = 'LoadFromSQLServer(' + @in_varServerName + ', "", "", 256, , , , ' + @in_varPackageName + ')';
16: -- CREATE THE OBJECT.
17: EXEC @hr = master..sp_OACreate 'DTS.package', @object OUT;
18: IF @hr <> 0
19: BEGIN
20: -- Trapping error if object not created
21: EXEC master..sp_OAGetErrorInfo @object, @src OUT, @desc OUT
22: SELECT @err=@@error
23: SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
24: if @err<>0
25: goto Catch
26: END
27: -- GET THE DTS PACKAGE REFRENCE.
28:
29: EXEC @hr = master..sp_OAMethod @object, @Val, NULL;
30: IF @hr <> 0
31: BEGIN
32: -- Trapping error if Execute failed
33: EXEC master..sp_OAGetErrorInfo @object, @src OUT, @desc OUT
34: SELECT @err=@@error
35: SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
36: if @err<>0
37: goto Catch
38: END
39:
40: -- EXECUTE THE DTS PACKAGE.
41: EXEC @hr = master..sp_OAMethod @object, 'Execute'
42: IF @hr <> 0
43: BEGIN
44: -- Trapping error if Execute failed
45: EXEC master..sp_OAGetErrorInfo @object, @src OUT, @desc OUT
46: SELECT @err=@@error
47: SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
48: if @err<>0
49: goto Catch
50: END
51:
52: goto End
53:
54:
55: Catch:
56:
57: SELECT @errDesc=Description from master..sysmessages WHERE error=@err
58: RAISERROR (@errDesc,16,1)
59: return @err
60:
61: End:
62:
63: return 0
64: GO