Hello again, Can anybody tell me what the return values of system function xp_write_file() are (in SA12)? Documentation only says that "It returns 0 if successful, and non-zero if it fails." So what are those non-zero values and their meanings?

asked 09 Aug '11, 01:25

Arthoor's gravatar image

Arthoor
1.1k264056
accept rate: 0%


I don't believe the lack of documentation is intentional. Here's a short summary:

  • if you do not have permission to execute xp_write_file(), the procedure returns -1 and an SQL error is generated (SQLCODE -121).
  • If there is a problem opening the file (an error was returned from the OS OPEN() call) then the procedure returns +1.
permanent link

answered 09 Aug '11, 09:07

Glenn%20Paulley's gravatar image

Glenn Paulley
10.7k568104
accept rate: 43%

The only non-zero values that are returned from the xp_write_file() function are the values -1 and +1. The value "1" indicates that the write failed. (Sorry, no additional information at this time is available).

Just in case the return value ever changes in the future I would suggest that you write your code as:

declare @rv int;
set @rv = xp_write_file( ... );
if @rv != 0 then
    -- handle error condition
else
    -- write succeeded.
end if;
permanent link

answered 09 Aug '11, 08:51

Mark%20Culp's gravatar image

Mark Culp
22.5k9129264
accept rate: 40%

edited 10 Aug '11, 12:28

Martin's gravatar image

Martin
8.6k114149237

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×405
×20

question asked: 09 Aug '11, 01:25

question was seen: 1,299 times

last updated: 10 Aug '11, 12:28