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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 error returning by xp_cmdshell

Author  Topic 

trans53
Starting Member

2 Posts

Posted - 2006-02-25 : 14:07:43
Hi all, this is what i am trying to do:

Run the following BCP command without no_output.
If destination folder not exists then i am getting the following message in QA :

SQLState = S1000, NativeError = 0
Error = [Microsoft][ODBC SQL Server Driver]Unable to open BCP host data-file
NULL

How can i catch this error in the code and return from the stored procedure?

Currently when i print @@error i got 0 which assumes all correct.

Thanks


this is the code i am running from QA:

DECLARE @SQLQuery VARCHAR(1000),
@FK_BATCH_ID INT,
@CMD VARCHAR(1000),
@ServerName VARCHAR(50),
@User VARCHAR(50),
@Password VARCHAR(50),
@FileLocationNew VARCHAR(64),
@FileName VARCHAR(50)

SELECT @FK_BATCH_ID = 231
SELECT @ServerName = @@SERVERNAME
SELECT @User = 'test'
SELECT @Password = 'test'
SELECT @FileName = 'RAA_02242006181851.ach'

SELECT @FileLocationNew = '\\SERVERNAME\FOLDER\NEW\'

PRINT @ServerName
PRINT @FileLocationNew
PRINT @FileName

SET @SQLQuery = 'SELECT ENTRY_RECORD FROM TABLE WHERE FK_ID = ' +
CAST(@FK_BATCH_ID AS VARCHAR(10)) '

SET @CMD = 'bcp "' + @SQLQuery + '" queryout '+ @FileLocationNew + @FileName +
' -S ' + @ServerName + ' -U ' + @User + ' -P ' + @Password + ' -w '
exec master..xp_cmdshell @CMD --, no_output

print @@error
   

- Advertisement -