You can also run DTS packages via their COM API using sp_OACreate. This
approach is more powerful than dtsrun in a few ways, including access to
error information. Here's an example:
CREATE PROCEDURE sp_CallDTSPkg
@Packagename varchar(1000),
@file_name varchar(1000)
AS
SET NOCOUNT ON
declare @PackageServer Varchar(20)
Set @packageServer = 'servernamehere'
DECLARE @DTSPkg int
DECLARE @hr int
DECLARE @src varchar(50)
DECLARE @Descr varchar(100)
DECLARE @result int
DECLARE @errorinfo varchar(1000)
--Create a reference to the Package
EXEC @hr = sp_OACreate 'DTS.Package', @DTSPkg OUT
if @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo NULL, @src OUT, @descr OUT
--there was an error
set @result = 0
END
ELSE
BEGIN
set @result = 1
--no error continue to next step
--Connect to it
EXEC @hr = sp_OAMethod @DTSPkg, 'LoadFromSQLServer',NULL,@ServerName =
@PackageServer,@Flags = 256, @PackageName = @PackageName
if @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @DTSPkg, @src OUT, @descr OUT
--there was an error
select @errorinfo = 'OLE Automation Error Information
Source: ' + @source + ' Description: ' + @description
print @errorinfo
set @result = 0
END
ELSE
BEGIN
exec @hr = sp_OASetProperty @DTSPkg, 'GlobalVariables("file_name").value',
@file_name
set @result = 1
--no error continue to next step
EXEC @hr = sp_OAMethod @DTSPkg, 'Execute'
if @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @DTSPkg, @src OUT, @descr OUT
--there was an error
select @errorinfo = 'OLE Automation Error Information
Source: ' + @source + ' Description: ' + @description
print @errorinfo
set @result = 0
END
ELSE
BEGIN
--there was no error
set @result = 1
END
END
END
HTH
Regards,
Greg Linwood
SQL Server MVP
[quoted text, click to view] "MS User" <sqlman@sql.com> wrote in message
news:eNMI9oapEHA.3392@TK2MSFTNGP15.phx.gbl...
> SQL 2K
>
> Please provide any thoughts on handling DTS error while called from a SQL
> job.
>
> My SQL Job starts a DTS using dtsrun utility and when the DTS fails, I
> don't
> have much details.
>
> If I setup in DTS , Property -> Logging -> Error handling , will I get
> all
> the detailed error information on a transformation inside DTS.
>
> Thanks
> MS
>
>