Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
terrybogard4
Starting Member
1 Post |
Posted - 2012-08-22 : 13:18:49
|
I have the following stored procedure: CREATE PROCEDURE [dbo].[PName]AS declare @nmbr int, @counter int,@firstrow char, @destTable varchar(75), @importFile varchar(500),@filedir varchar(500) DECLARE @filename nvarchar(500)DECLARE @SIZE int,@error intDECLARE @fileobj INT , @fsobj INT,@exists intDECLARE @src VARCHAR(255), @desc VARCHAR(255)DECLARE @CMD VARCHAR(8000)set @filedir = 'C:\'set @counter =0set @nmbr = (select count (*) from table1)while @counter <@nmbrbeginset @counter = @counter +1select @destTable=destTable, @importFile=importfile, @firstrow=firstrow from table_config where id = @counterset @filename = @filedir + '\' + @importFileEXEC sp_OACreate 'Scripting.FilesystemObject', @fsobj OUTIF @error <> 0BEGINEXEC sp_OAGetErrorInfo @fsobj, @src OUT, @desc OUTSELECT error=CONVERT(varbinary(4),@error), Source=@src, Description=@descRETURNENDexec @error = sp_OAMethod @fsobj, 'FileExists', @exists OUT,@filenameif @exists <>0beginexec sp_OAMethod @fsobj, 'GetFile' , @fileobj OUTPUT,@filenameEXEC @SIZE = sp_OAGetProperty @fileobj, 'Size', @Size OUTEXEC @error = sp_OADestroy @fileobjEXEC @error = sp_OADestroy @fsobjif @SIZE >'0'beginSET @CMD = 'TRUNCATE TABLE ' + @destTableEXEC (@CMD)?SET @CMD = 'BULK INSERT ' + @destTable + ' FROM ''' + @FileName + ''' WITH (FIRSTROW = ' + @firstrow + ', FIELDTERMINATOR = ''|'',ROWTERMINATOR = '''+CHAR(10)+''' )'EXEC (@CMD)endendendGO??The stored procedure runs fine when I execute it using:??exec 'PName'??But when I call it from a SQL Job in SQL Server Agent, the job step hangs. What am I doing wrong???Terry |
|
jackv
Master Smack Fu Yak Hacker
2179 Posts |
Posted - 2012-08-22 : 14:12:27
|
Does the account running the job have the same permissions?Jack Vamvas--------------------http://www.sqlserver-dba.com |
|
|
|
|
|
|
|