Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ORA-22288:文件或LOB操作FILEOPEN失败系统找不到指定的路径_C#_Sql_Oracle_Oracle11g - Fatal编程技术网

C# ORA-22288:文件或LOB操作FILEOPEN失败系统找不到指定的路径

C# ORA-22288:文件或LOB操作FILEOPEN失败系统找不到指定的路径,c#,sql,oracle,oracle11g,C#,Sql,Oracle,Oracle11g,我有一个表,它有三列 表名为BFILETABEL 在我的C代码中,我试图创建一个目录,然后将其插入表行中 private void bFileInsertFileInOracle(string fileName) { string[] getFileNameFromAddress = fileName.Split('\\'); myConnection.Open(); OracleCommand createFolder = ne

我有一个表,它有三列

表名为BFILETABEL

在我的C代码中,我试图创建一个目录,然后将其插入表行中

private void bFileInsertFileInOracle(string fileName)
        {
        string[] getFileNameFromAddress = fileName.Split('\\');

        myConnection.Open();
        OracleCommand createFolder = new OracleCommand();
        createFolder.Connection = myConnection;

        createFolder.CommandText = "CREATE OR REPLACE DIRECTORY bfileimages AS 'C:\\TEMP\\bfileimages'";
        createFolder.ExecuteNonQuery();

        String strSQL = "INSERT INTO BFILETABEL VALUES (" + bFileFileIDS + ",'" + fileName + "', BFILENAME('BFILEIMAGES', '" + getFileNameFromAddress[getFileNameFromAddress.Length - 1] + "'))";

        OracleCommand cm = new OracleCommand();
        cm.Connection = myConnection;
        cm.CommandText = strSQL;
        cm.ExecuteNonQuery();

        myConnection.Close();
        }
在该文件名中,是图像文件的路径。执行时不显示异常。我的意思是没有异常显示像用户权限异常一样,没有显示任何内容。但当我选择该文件并打开它时,会生成异常

ORA-22288: file or LOB operation FILEOPEN failed
The system cannot find the path specified.
该函数的代码是

        private void bFileShow_Click(object sender, EventArgs e)
        {
        int getNumber = Convert.ToInt16(BFileTextboxImgID.Text);

        myConnection.Open();
        OracleCommand ocmd = new OracleCommand("select * from BFILETABEL where fileid=" + getNumber + "", myConnection);
        ocmd.InitialLOBFetchSize = 2;
        OracleDataReader rd = ocmd.ExecuteReader();
        rd.Read();
        OracleBFile getBlob = rd.GetOracleBFile(2);
        getBlob.OpenFile();   // exception occurs at that line 
        if (getBlob.FileExists)
            {
            label1.Text = getBlob.FileName.ToString(); 
            getBlob.OpenFile();
            byte[] buffer = new byte[100];

            getBlob.Seek(0, SeekOrigin.Begin);
            getBlob.Read(buffer, 0, 100);
            MemoryStream ms = new MemoryStream(buffer);
            blobPictureBox.Image = new Bitmap(ms);
            }
        myConnection.Close();
        }

当我把文件放在C:\TEMP中时,它就工作了。我的意思是,例如,如果用户想要上传blue hills.jpg。我将文件复制到C:\TEMP中,然后执行如下查询

CREATE or REPLACE DIRECTORY directoryName as 'C:\TEMP'
插入查询是

INSERT INTO table_name VALUEs ('1',BFILENAME('DIRECTORYNAME','blue hills.jpg'))

根据您的代码,我假设该文件已经位于c:\temp目录中。因此,您仅将c:\temp中的现有文件与Oracle上的bfile指针相关联。如果目标文件夹中还没有文件,请使用存储过程中列出的代码从C中插入。此代码取自我们开发的Invantive Vision文档管理系统,但您可以随意以任何方式使用这部分代码。上传后,您需要在bfile表中插入指针

进一步检查您是否正在使用ODP.Net和一些最新版本。它修复了许多常见问题

还应始终在insert语句中对列列表进行编码。当Oracle获得了一个疯狂的一天,并且您的列被重新排序时,插入将神奇地失败或产生有趣的效果:

String strSQL = "INSERT INTO BFILETABEL VALUES (" + bFileFileIDS + ",'" + fileName + "', BFILENAME('BFILEIMAGES', '" + getFileNameFromAddress[getFileNameFromAddress.Length - 1] + "'))";
变成

String strSQL=插入bFileTable COLUMN1、COLUMN2、COLUMN3、, COLUMN4值+bFileId+,“+fileName+”, BFILENAME'BFILEIMAGES','+ getFileNameFromAddress[getFileNameFromAddress.Length-1]+'

建议在重复执行或正确转义值时,使用参数更快的语句替换insert语句。可能有人使用了一个带有引号的文件名,这将导致解析SQL时出错

在目录中上载blob的示例:

procedure write_blob_to_file
( p_directory varchar2
, p_filename  varchar2
, p_blob      blob
)
as
  l_fh                       utl_file.file_type;
  l_blob_length              integer;
  l_buffer                   raw(32767);
  l_chunk_size               binary_integer := 32767;
  l_blob_position            integer := 1;
begin
  l_blob_length := dbms_lob.getlength(p_blob);
  l_fh := utl_file.fopen(p_directory, p_filename, 'wb', l_chunk_size);
  --
  -- Write the BLOB to file in chunks
  --
  while l_blob_position <= l_blob_length
  loop
    if l_blob_position + l_chunk_size - 1 > l_blob_length
    then
      l_chunk_size := l_blob_length - l_blob_position + 1;
    end if;
    dbms_lob.read(p_blob, l_chunk_size, l_blob_position, l_buffer);
    utl_file.put_raw(l_fh, l_buffer, true);
    l_blob_position := l_blob_position + l_chunk_size;
  end loop;
  utl_file.fclose(l_fh);
exception
  when others
  then
    --
    -- Close file if necessary.
    -- Ignore any errors.
    --
    begin
      if utl_file.is_open(l_fh)
      then
        utl_file.fclose(l_fh);
      end if;
    exception
      when others
      then
        null;
    end;
    --
    rollback;
    itgen_error_handler.add_to_inner_stack;
    raise;
end;

我希望这对您有所帮助。

您的数据库服务器上是否存在C:\TEMP\bfileimages\文件夹?该文件夹不存在,但我尝试了C:\TEMP,该文件夹存在,但我仍然收到该错误。该图像如何,文件夹C:\TEMP-中的图像是否在数据库服务器上,而不是在客户端PC上?Oracle具有访问该文件夹的读/写权限吗?
procedure write_blob_to_file
( p_directory varchar2
, p_filename  varchar2
, p_blob      blob
)
as
  l_fh                       utl_file.file_type;
  l_blob_length              integer;
  l_buffer                   raw(32767);
  l_chunk_size               binary_integer := 32767;
  l_blob_position            integer := 1;
begin
  l_blob_length := dbms_lob.getlength(p_blob);
  l_fh := utl_file.fopen(p_directory, p_filename, 'wb', l_chunk_size);
  --
  -- Write the BLOB to file in chunks
  --
  while l_blob_position <= l_blob_length
  loop
    if l_blob_position + l_chunk_size - 1 > l_blob_length
    then
      l_chunk_size := l_blob_length - l_blob_position + 1;
    end if;
    dbms_lob.read(p_blob, l_chunk_size, l_blob_position, l_buffer);
    utl_file.put_raw(l_fh, l_buffer, true);
    l_blob_position := l_blob_position + l_chunk_size;
  end loop;
  utl_file.fclose(l_fh);
exception
  when others
  then
    --
    -- Close file if necessary.
    -- Ignore any errors.
    --
    begin
      if utl_file.is_open(l_fh)
      then
        utl_file.fclose(l_fh);
      end if;
    exception
      when others
      then
        null;
    end;
    --
    rollback;
    itgen_error_handler.add_to_inner_stack;
    raise;
end;