Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server DTS
|
SQL Server DTS Discussion specific to Data Transformation Service with SQL Server. General SQL Server discussions should use the general SQL Server forum. Readers of the book Professional SQL Server 2000 DTS with questions specific to that book should post in that book forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server DTS section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 11th, 2010, 10:37 AM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default sp_OAGetProperty help

I'm trying to call a DTS from a stored procedure. It works if I use dts.package in visual basic, but I don't want to install sql client files on every machine I want to be able to run this. So with that, can someone tell me what I'm doing wrong? Everything seems to work up until the SetProperty statement. When I use the GetProperty method, it returns null. I have verified that @inputfile contains the value I want.

Please help before I go insane.

-- CODE --
set @server = 'MyServer'
set @PkgPwd = ''
set @PkgName = 'MyPackage'

EXEC @hr = sp_OACreate 'DTS.Package', @oPKG OUTPUT
IF @hr <> 0
BEGIN
PRINT '*** Create Package object failed'
EXEC sp_displayoaerrorinfo @oPKG, @hr
RETURN 1
END
SET @Cmd = 'LoadFromSQLServer("' + @Server +'", "", "", 256, "' + @PkgPWD + '", , , "' + @PkgName + '")'
EXEC @hr = sp_OAMethod @oPKG, @Cmd, NULL
IF @hr <> 0
BEGIN
PRINT '*** LoadFromSQLServer Failed.'
EXEC sp_displayoaerrorinfo @oPKG, @hr
RETURN 1
END
EXEC @hr = sp_OASetProperty @oPKG,'GlobalVariables("inputfile").Value', @inputfile
IF @hr <> 0
BEGIN
PRINT '*** Set Property Failed'
EXEC sp_displayoaerrorinfo @oPKG, @hr
RETURN 1
END

declare @property nvarchar(254)
exec @hr = sp_OAGetProperty @oPKG,'GlobalVariables("inputfile")',@property OUT
if @hr<>0
begin
PRINT '*** Get Property Failed'
EXEC sp_displayoaerrorinfo @oPKG, @hr
select @oPKG
RETURN 1
end
select @property
EXEC @hr = sp_OAMethod @oPKG, 'Execute'
EXEC @hr = sp_OAMethod @oPKG, 'UnInitialize'
EXEC @hr = sp_OADestroy @oPKG
-- END CODE --
 
Old March 11th, 2010, 12:06 PM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

After some more research I've found that my syntax isn't right

it should be


EXEC @hr = sp_OASetProperty @oPKG,'GlobalVariables.item("inputfile").Value', @inputfile

Also, sp_OAGetProperty doesn't work if your output variable is nvarchar. It needs to be varchar.

Now that my input is working, I have to figure out why my package is failing :(









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.