Open a remote file using utl_file.fopen on Windows - oracle

I have to access a remote file in a different computer using utl_file.
This is what I did:
create a user with Adminstrator+Users+ora_db profile in the remote PC, the same user is created with the same role in my PC.
Run the Oracle Services using this administrator account
Map the remote directory under Windows
use the following command to configure and accesss the file:
create or replace directory REMOTE_LOG as '\\remote_shared_dir\log';
declare
f UTL_FILE.FILE_TYPE;
line VARCHAR2(32767) ;
begin
BEGIN
f := UTL_FILE.FOPEN('REMOTE_LOG','toto.txt','R',32764);
EXCEPTION WHEN OTHERS THEN
dbms_output.put_line('err '||sqlerrm);
END;
UTL_FILE.GET_LINE( f, line );
UTL_FILE.FCLOSE( f ) ;
end;
But it failed with:
[Error] Execution (7: 3): ORA-29282: invalid file ID
ORA-06512: at "SYS.UTL_FILE", line 735
ORA-06512: at line 13
When I remove the exception handler I instead see:
[Error] Execution (7: 3): ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 8
What am I doing wrong?

Related

ORA-29283: invalid file operation when calling utl_file.fopen on Windows server 2016

Most of the answers I've seen are for Linux. Windows permissions have an element of black magic about them. This is Windows Server 2016.
I created the d:\data\transfer\sirius\ directory on the Oracle database server.
As SYSDBA I do the following:
create or replace directory SIRIUS_DIR as 'd:\data\transfer\sirius\';
grant read,write on directory SIRIUS_DIR to SIRIUS;
Then on another server, in a SQL*Plus session as the SIRIUS user, I run:
DECLARE myFile utl_file.file_type;
BEGIN
myFile := utl_file.fopen('SIRIUS_DIR ', 'random.txt', 'w', 32000);
END;
/
Which gives:
ERROR at line 1:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 41
ORA-06512: at "SYS.UTL_FILE", line 478
ORA-06512: at line 3
How to proceed?
Figured it out. You need to grant full access to the ORA_INSTALL group to the directory in question on the database. According to the Oracle configuration docs:
The ORA_INSTALL group contains all the Oracle Home Users for all
Oracle homes on the server.
Thanks to this kindly blogger for his solution.

ORA-22288 when trying to read BLOB from Windows directory

I am trying to read BLOB from Windows directory located on the Oracle 11g DB server:
create or replace directory BLOB_DIR as 'C:\data\images';
grant read, write on directory BLOB_DIR to public;
set serveroutput on;
declare
l_bfile BFILE;
begin
l_bfile := BFILENAME('BLOB_DIR', 'blob.jpg');
DBMS_LOB.fileopen(l_bfile, DBMS_LOB.file_readonly);
DBMS_LOB.fileclose(l_bfile);
end;
/
However, I am getting the following error:
ORA-22288: file or LOB operation FILEOPEN failed
ORA-06512: at "SYS.DBMS_LOB", line 744
ORA-06512: at line 5
I checked the directory and file exist and all the permissions are given to Everyone.
What am I doing wrong? How to get more specific error message?

Cannot write file xml output form a procedure - ORA-06512: a "SYS.UTL_FILE"

in our production environment we use a procedure that read from our DB Oracle 12c and write about 2000 files xml in output on the filesystem, all in the same directory.
Now we have a problem: after that 1400 files are already writed, the procedure fails with error:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
There is enough space on the filesystem to write the files and i have already checked the permissions.
In the procedure we call:
xdb.dbms_xslprocessor.clob2file(xml_document,R_FILE_FOLDER,substr(xml_file_name,0,instr(xml_file_name,'.',-1)-1)||'.unc',nls_charset_id('AL32UTF8'));
Thank you

Invalid file operation in pl/sql

I was learning PL/SQL and I have been getting this error as "invalid file operation since long"
The code is as follows:
SET SERVEROUTPUT on;
CREATE or replace directory DESKTOP as 'C:\Users\Gadre\Desktop';
declare
v1 varchar2(32767);
f1 utl_file.file_type;
begin
f1 :=utl_file.fopen('DESKTOP','test.docx','r');
dbms_output.put_line('HELLO WORLD');
end;
The error is:
Error report:
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 5
29283. 00000 - "invalid file operation"
*Cause: An attempt was made to read from a file or directory that does
not exist, or file or directory access was denied by the
operating system.
*Action: Verify file and directory access privileges on the file system,
and if reading, verify that the file exists.
The file does exist surely. Plus I am through admin access so I think I do have privileges.

UTL_FILE.FREMOVE raises "file remove operation failed"

I have this code
BEGIN
UTL_FILE.FREMOVE('DIR_USERS', 'user.jpg');
END;
It raises
ORA-20000: ORA-29291: file remove operation failed
ORA-6412: at "SYS.UTL_FILE", line 251
ORA-6512: at "SYS.UTL_FILE", line 1230
ORA-6512: at "USERS.PKG_USERS", line 177
I think that the error is in the built-in function of the UTL_FILE package because when I used the function UTL_FILE.FRENAME, it also raises the same error.
What could be the problem here?
Does the file exist?
Be aware that UTL_FILE operations are executed at the OS as the user that the oracle processes are running as, usually "oracle". So, does the "oracle" user have rwx privs on the directory containing the file? So "oracle" have rw permission on the file?
The file could be simply hold by another program. I got the same issue:
SQL> begin
2 utl_file.FREMOVE('GK_IMP_KONN_NEW', 'PDT17_2016-05-26T11-32-38');
3 end;
4 /
begin
*
FEHLER in Zeile 1:
ORA-29291: Datei konnte nicht entfernt werden
ORA-06512: in "SYS.UTL_FILE", Zeile 251
ORA-06512: in "SYS.UTL_FILE", Zeile 1230
ORA-06512: in Zeile 2
After uncountable tries I closed the SQL Developer and tried it again:
SQL> begin
2 utl_file.FREMOVE('GK_IMP_KONN_NEW', 'PDT17_2016-05-26T11-32-38');
3 end;
4 /
PL/SQL-Prozedur erfolgreich abgeschlossen.
Success!

Resources