I truly appreciate all the help. I am learning (Just not certain what I am learning yet is all)
You are probably getting tired of me by now, but I am really stuck and cannot either find what I need or understand it if I am finding it but here goes again.
This time I receive:
first I print out my SQL Command
******EXEC sp_OAMethod 16711422, 'LoadFromSQLServer ("TERRYLAPTOP", "", "", 256, , , , "DTS_ImportInventory")', null
Then I receive this error.
Server: Msg 8178, Level 16, State 5, Line 0
Prepared statement '(@PKG nvarchar(30),
@WhichServer nvarchar(255), ' expects parameter @PKG, which was not supplied.
Apparently, If I understand this correctly, SP_OAMethod expects a integer as the first argument.
But, again if I understand this correctly, sp_executeSQL accepts nVarChar/VarChar/Char argument only.
There must be some way to do this that I am not finding.
If I attempt to convert @PKG back to an int after begining execution like this:
set @SQL_Command = N'EXEC sp_OAMethod cast(' + @PKG + ' as int), ' + char(39) + 'LoadFromSQLServer ("' + @WhichServer + '", "", "", 256, , , , "' + @package + '")' + char(39) +', null'
which prints as:
EXEC sp_OAMethod cast(16711422 as int), 'LoadFromSQLServer ("TERRYLAPTOP", "", "", 256, , , , "DTS_ImportOrders")', null
I receive Incorrect syntax near '16711422'. (Somewhat expected, but I needed to be certain)
Current code 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 varchar(30)
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
set @PKG = cast( @oPKG as nvarchar(30))
set @WhichServer = @@Servername
set @package = @PackageName
SET @ParamDef=N'@PKG nvarchar(30),
@WhichServer nvarchar(255),
@package nvarchar(30) '
print '***'+@PKG
Print '****'+@WhichServer
Print '***'+@Package
set @SQL_Command = 'EXEC sp_OAMethod ' + @PKG +', ' + char(39) + 'LoadFromSQLServer ("' + @WhichServer + '", "", "", 256, , , , "' + @package + '")' + char(39) +', null'
print '******'+@SQL_command
exec sp_ExecuteSQL @SQL_Command, @ParamDef
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
Terry (cyberbiker)