none
C#(引用System.Data.OracleClient)写入oracle blob类型的字段,如果size大于一定值会出差,看怎样解决 RRS feed

  • 问题

  •         // 类成员变量定义 begin
            OracleConnection m_ora_conn;// 声明数据库连接对象
            OracleDataAdapter m_da_1;   // 声明数据桥接器对象
            DataSet m_ds_1;               // 声明数据集对象
            String m_cv_conn_str;
            String m_cv_additional_file_name; // 附件的名称
            // 类成员变量定义 end

                m_cv_conn_str = "data source=ORCL_127.0.0.1;user  id=project_task_memo;pwd=newone;";    
                m_ora_conn = new OracleConnection(m_cv_conn_str);

                m_ora_conn.Open();

                openFileDialog1.Title = "选择附件";
                //判断是否选择了头像

                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    m_cv_additional_file_name = openFileDialog1.FileName;
                }
                else
                {
                    m_cv_additional_file_name = "";
                    return;
                }

                FileStream fs = new FileStream(m_cv_additional_file_name, FileMode.Open);
                //创建了二进制数组  
                byte[] blob = new byte[fs.Length];
                fs.Read(blob, 0, blob.Length);
                fs.Close();


                if (m_ora_conn.State != ConnectionState.Open)
                    return;

                OracleCommand ora_cmm = new OracleCommand();
                ora_cmm.Connection = m_ora_conn;
                ora_cmm.CommandText = "P_TEST_1";
                ora_cmm.CommandType = CommandType.StoredProcedure;

                ora_cmm.Parameters.Clear();
                ora_cmm.Parameters.Add("pi_1", OracleType.VarChar, 32).Value = "c1";
                ora_cmm.Parameters.Add("pi_2", OracleType.VarChar, 32).Value = "c2";
                //ora_cmm.Parameters.Add("pi_b", OracleType.Blob, blob.Length);
                //ora_cmm.Parameters["pi_b"].Value = blob;

                OracleParameter parm1 = new OracleParameter();
                parm1.ParameterName = "PI_B";
                parm1.OracleType = OracleType.Blob;
                parm1.Direction = ParameterDirection.Input;
                parm1.Value = blob;
                parm1.Size = blob.Length;

                ora_cmm.Parameters.Add(parm1);

                try
                {
                    ora_cmm.ExecuteNonQuery();
                }
                catch (Exception ep)
                {
                    String str1 = ep.Message; // 读入的文件过大时会出错
                } 

     

    2010年9月3日 3:21