问题描述
我需要通过压缩将数据插入到oracle blob列中.
我尝试将压缩与GzipStream,DflateStream一起使用.但是压缩数据后,gzip对象中的数据为空(\ 0 \ 0 \ 0 \ 0).
在使用c#插入到blob列之前,有什么方法可以压缩数据. 必须压缩. 我能够以正常方式插入字节数据.我需要一种在压缩后插入的方法.
插入方法()
{
byte []字节[]定义= GetGzipCompressedBytes(officeDocumentObj.Definition);
/>//字节定义= ASCIIEncoding
字节[]标题= GetGzipCompressedBytes(officeDocumentObj.Title);跟踪文件
////TraceUtil.WriteErrorLine("连接字符串:" + base.Connection.ConnectionString);
conn.Open(); Command
OracleCommand addSlideinfo = new OracleCommand();
addSlideinfo.Connection = conn; .Text;
addSlideinfo.Parameters.Add("ID",O racleType.VarChar,50).Value ="officeDocumentObj.ID";
addSlideinfo.Parameters.Add("Definition",OracleType.Blob).Value =定义;
"UserID",OracleType.VarChar,20).Value ="officeDocumentObj.UserID";
addSlideinfo.Parameters.Add("ImagePath",OracleType.VarChar,250).Value="officeDocumentObj. ;;
addSlideinfo.Parameters.Add("Type",OracleType.VarChar,50).Value ="officeDocumentObj.Type.ToString()". DateAdded",OracleType.DateTime.Value =". officeDocumentObj.DateAdded'';
addSlideinfo.Parameters.Add(``SlideTitle'',OracleType.Blob).Value = title;
/>/> insertStatus = addSlideinfo.ExecuteNonQuery();
}
[] GetGzipCompressedBytes(string streaminfo)
{
/>///OracleLob blob = null; ;
MemoryStream mstream = new MemoryStream();
mstream.Write(databytes,0,databytes.Length); ,CompressionMode.Compress);
byte [] byte [] gZipdatabytes =新的byte [databytes.Length];
gZip.Write(gZipdatabytes,0,gZipdatabytes.Length);
gZip.Close();
//blob.Write(gZipdatabytes,0,gZipdatabytes.Length);
br/>}
谢谢
chandra
Hi, i need to insert the data to the oracle blob column by compressing.
i tried using compressing with GzipStream, DflateStream. But after compressing the data, data in gzip object is empty(\0\0\0\0).
is there any way to compress the data before inserting into blob column using c#. Compression is must. i am able to insert the byte data in normal way. I need a way to insert after compressing. below is the code, this is not working..just check this out.
insert method()
{
byte[] definition = GetGzipCompressedBytes(officeDocumentObj.Definition);
//byte definition =ASCIIEncoding
byte[] title = GetGzipCompressedBytes(officeDocumentObj.Title);
conn = base.Connection;
//write the connection string in the trace file
//TraceUtil.WriteErrorLine("Connection string: " + base.Connection.ConnectionString);
conn.Open();
// Construct INSERT Command
OracleCommand addSlideinfo = new OracleCommand();
addSlideinfo.Connection = conn;
addSlideinfo.CommandText = sbQuery.ToString();
addSlideinfo.CommandType = CommandType.Text;
addSlideinfo.Parameters.Add("ID", OracleType.VarChar, 50).Value = "officeDocumentObj.ID";
addSlideinfo.Parameters.Add("Definition", OracleType.Blob).Value = definition;
addSlideinfo.Parameters.Add("UserID", OracleType.VarChar, 20).Value = "officeDocumentObj.UserID";
addSlideinfo.Parameters.Add("ImagePath", OracleType.VarChar, 250).Value = "officeDocumentObj.ImagePath";
addSlideinfo.Parameters.Add("Type", OracleType.VarChar, 50).Value = "officeDocumentObj.Type.ToString()";
addSlideinfo.Parameters.Add("DateAdded", OracleType.DateTime).Value =" officeDocumentObj.DateAdded";
addSlideinfo.Parameters.Add("SlideTitle", OracleType.Blob).Value = title;
int insertStatus = 0;
try
{
insertStatus = addSlideinfo.ExecuteNonQuery();
}
catch (Exception ex1)
{
}
}
private static byte[] GetGzipCompressedBytes(string streaminfo)
{
//OracleLob blob = null;
//blob = new OracleLob
byte[] databytes = ASCIIEncoding.Default.GetBytes(streaminfo);
MemoryStream mstream = new MemoryStream();
mstream.Write(databytes,0,databytes.Length);
Stream fstream = mstream;
GZipStream gZip = new GZipStream(fstream, CompressionMode.Compress);
byte[] gZipdatabytes = new byte[databytes.Length];
gZip.Write(gZipdatabytes, 0, gZipdatabytes.Length);
gZip.Close();
//blob.Write(gZipdatabytes, 0, gZipdatabytes.Length);
return gZipdatabytes;
}
thanks
chandra
推荐答案
使用(MemoryStream mstream = new MemoryStream())
using(MemoryStream mstream = new MemoryStream())
这篇关于使用C#的Oracle Blob压缩数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!