We want to write a downloaded file with scripting to a folder on the client machine. But the procedure write_client_file() seems to be missing. Has it been replaced? Has it something to do with having the proper rights. The function is mentioned in the help files and I would expect that the function would be available. The error we get:

Could not execute statement.
Procedure 'write_client_file' not found
SQLCODE=-265, ODBC 3 State="42S02"

asked 07 Apr '23, 03:47

Frank%20Vestjens's gravatar image

Frank Vestjens
1.3k344462
accept rate: 21%


That function should not be 'CALL'ed. It should be executed either as SELECT or via a SET var =. Here is an example:

set temporary option allow_write_client_file = 'on'; // permit write_client_file for current connection
select write_client_file( 'c:\temp\write_client_file.txt', 'Testing write_client_file with SELECT' );
set retval = write_client_file( 'c:\temp\write_client_file2.txt', 'Testing write_client_file with SET' );

-- but this will report Procedure 'write_client_file' not found
call write_client_file( 'c:\temp\write_client_file3.txt', 'Testing write_client_file with CALL'

It is also possible to further secure the feature with -sf.

permanent link

answered 07 Apr '23, 09:30

Chris%20Keating's gravatar image

Chris Keating
7.7k49127
accept rate: 32%

Check the documentation for write_client_file here. You need to ensure a number of privileges have been enabled/set before using this function.

Also, you must be using a client API that uses the CmdSeq protocol (ODBC, dblib). If you are using any of the other APIs then this function cannot be used. What client API are you using?

permanent link

answered 07 Apr '23, 07:38

Mark%20Culp's gravatar image

Mark Culp
24.9k10139297
accept rate: 41%

edited 07 Apr '23, 07:42

We're trying to run the function from within a script in the database.

But according to your comment this does not seem to be possible. This can only be achieved by creating a share on the client that is accessible from the server the database is running and then us xp_Write_file()

(07 Apr '23, 08:31) Frank Vestjens
Replies hidden

How and where do you execute that script? For example, it certainly is doable to run a script within a CmdSeq-based client on a user machine that accesses files on the client machine or on net shares that client can access... We do so.

(07 Apr '23, 12:51) Volker Barth

From a client application we call a stored procedure where we want to pass the location where to store the file on the client. The procedure first downloads a binary file using a web service and then needs to store it on the passed location on the client. The client application is a windows application that uses the ODBC driver to connect to the database.

(08 Apr '23, 05:57) Frank Vestjens
Replies hidden

That should work but when the client file read/write is issued within a stored procedure (in contrast to via directly from the client code), it requires a particular ODBC callback, see here, in addition to the required privilege.

(08 Apr '23, 12:05) Volker Barth
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:

×28
×24

question asked: 07 Apr '23, 03:47

question was seen: 1,531 times

last updated: 20 Dec '23, 16:44