racle 8i(中文编码)+VS2005(.NET 2.0) 客户端连接使用的是微软的OralceClient类型问题说明:
1、如果BinaryFormatter采用默认的序列化格式,在反序列化的时候会出现乱码(只是有的表,DataSet表中放置了多个表)
2、如果BinaryFormatter采用XsdString序列化格式,在反序列化的时候如果表中包含Blob字段会出现乱码,其它没有包含的好像不会出现(只是有的表,DataSet表中放置了多个表)
//对导出的数据采取加密压缩的方式
//其中ICryptoTransform encryptor是用来进行加密序列化的文件
导出导入代码:
采取下面的方式进行导出数据然后序列化:
private static bool BinarySerialize(ICryptoTransform encryptor, String FileName, DataSet ds, out String ErrorMessage)
{
try
{
FileStream fs = new FileStream(FileName, FileMode.Create);
BinaryFormatter formatter = new BinaryFormatter();
CryptoStream encStream = new CryptoStream(fs, encryptor, CryptoStreamMode.Write);
GZipStream comp = new GZipStream(encStream, CompressionMode.Compress, true);
//(DataSetSurrogate 类型是微软提供的DataSet包装类)
DataSetSurrogate dss=new DataSetSurrogate(ds);
BufferedStream bs = new BufferedStream(comp);
try
{
formatter.Serialize(bs, dss);
bs.Close();
comp.Close();
encStream.FlushFinalBlock();
encStream.Close();
fs.Close();
ErrorMessage = String.Empty;
return true;
}
catch (Exception e)
{
LogHelper.Debug("BinarySerialize出现错误:" + e.Message);
ErrorMessage = e.Message;
return false;
//throw;
}
finally
{
bs.Close();
comp.Close();
encStream.Close();
fs.Close();
}
}
catch (Exception e)
{
ErrorMessage = e.Message;
LogHelper.Debug("BinarySerialize出现错误:" + e.Message);
return false;
}
}
采用下面的方式反序列化:
private static DataSet BinaryDeSerialize(ICryptoTransform DeEncryptor, String FileName, out String ErrorMessage)
{
FileStream fs = null;
BinaryFormatter formatter = null;
CryptoStream encStream = null;
GZipStream comp = null;
BufferedStream bs = null;
try
{
fs = new FileStream(FileName, FileMode.Open);
formatter = new BinaryFormatter();
encStream = new CryptoStream(fs, DeEncryptor, CryptoStreamMode.Read);
comp = new GZipStream(encStream, CompressionMode.Decompress);
bs = new BufferedStream(comp);
try
{
DataSetSurrogate dss = (DataSetSurrogate)formatter.Deserialize(bs);
//bs.Close();
//comp.Close();
//encStream.Close();
//fs.Close();
ErrorMessage = String.Empty;
return dss.ConvertToDataSet();
}
catch (Exception e)
{
LogHelper.Debug("BinarySerialize出现错误:" + e.Message);
ErrorMessage = e.Message;
return null;
//throw;
}
}
catch (Exception e)
{
LogHelper.Debug("BinarySerialize出现错误:" + e.Message);
ErrorMessage = e.Message;
return null;
}
finally
{
bs.Close();
comp.Close();
encStream.Close();
fs.Close();
}
}

最新回复
egghead008 (2008-8-28 09:19:10)
egghead008 (2008-8-28 09:21:33)
egghead008 (2008-8-28 09:40:10)
egghead008 (2008-8-28 10:32:09)
zzWind (2008-9-26 15:43:47)