Please bear with me, but I am becoming more confused by the minute.
I now am receiving the error:
Server: Msg 245, Level 16, State 1, Procedure sp_ImportAll, Line 33
Syntax error converting the varchar value 'EXEC sp_OAMethod ' to a column of data type int.
Additionally, the "print '*****'+@SQL_Command" does not print.
I am not certain why. It was printing until I changed the Set @SQL_Command variable to the current line which was where I found my syntax error (Missing single quotes).
Line 33 is where I execute the sp_executeSQL.
Procedure follows:
CREATE PROCEDURE [sp_ImportAll] @path varchar(255), @Pack Int as
declare @hr int, @oPKG int, @PackageName varchar(30), @SQL_Command nvarchar(500),@WhichServer nvarchar(255),@ParamDef nvarchar(400), @Server nvarchar(255),
@package nvarchar(30),@PKG int
set @PackageName =
case @Pack
when 1 then 'DTS_ImportOrders'
when 2 then 'DTS_ImportInventory'
when 3 then 'DTS_ImportSalesman'
when 4 then 'DTS_ImportCustomer'
end
EXEC @hr = sp_OACreate 'DTS.Package', @oPKG out
IF @hr <> 0
BEGIN
PRINT '*** Create Package object failed'
EXEC sp_OAGeterrorinfo @oPKG, @hr
RETURN
END
--DTSSQLServerStorageFlags :
--- DTSSQLStgFlag_Default = 0
--- DTSSQLStgFlag_UseTrustedConnection = 256
set @WhichServer = @@servername
SET @ParamDef=N'@PKG int,
@Server nvarchar(255),
@package nvarchar(30) '
set @SQL_Command ='EXEC sp_OAMethod ' + @oPKG +', ' + char(39) + 'LoadFromSQLServer ("' + @WhichServer + '", "", "", 256, , , , "' + @packagename + '")' + char(39) +', null'
print '******'+@SQL_command
exec sp_ExecuteSQL @SQL_Command, N'@oPKG int, @WhichServer nvarchar (255), @packagename nvarchar(30)'
IF @hr <> 0
BEGIN
PRINT '*** ' + @packagename +' failed!'
EXEC sp_OAGeterrorinfo @oPKG, @hr
RETURN
END
EXEC @hr = sp_OASetProperty @oPKG, 'GlobalVariables("sFileName").Value', @path
IF @hr <> 0
BEGIN
PRINT '*** GlobalVariable Assignment Failed'
EXEC sp_OAGeterrorinfo @oPKG, @hr
RETURN
END
EXEC @hr = sp_OAMethod @PKG, 'Execute'
IF @hr <> 0
BEGIN
PRINT '*** Import operation failed unexpectedly'
EXEC sp_OAGeterrorinfo @oPKG , @hr
RETURN
END
GO
Also, I do not think that I need the // in this case.
I am not totally certain of that, but based on experimentation I feel I do not.
I have individual sp's coded for each DTS package that work very well with the server hardcoded as either "(local)" or "TerryLaptop".
Terry (cyberbiker)