19. April 2013 09:21
19. April 2013 09:33
In the new Version, the BLOB compression is no longer a proprietary format, ...
19. April 2013 09:38
2. Juni 2013 07:17
internal string ReadNoteDate(int Sqlkey)
{
try
{
string retStr = null;
#region SQL-Query
SqlConnection myCon = new SqlConnection();
myCon.ConnectionString = BuildConStr(MyServerInstance, MyDatabase);
SqlCommand myCommand = new SqlCommand("Select Note FROM [Record Link] WHERE [Link ID] = @LinkId", myCon);
SqlParameter myParameter = new SqlParameter("@LinkId", System.Data.SqlDbType.Int);
myParameter.Value = Sqlkey;
myCommand.Parameters.Add(myParameter);
myCon.Open();
#endregion
SqlDataReader myReader = myCommand.ExecuteReader();
if (myReader.HasRows == true)
{
if (myReader.Read())
{
MemoryStream outsqlstream = new MemoryStream();
// Read with this startindex because NAV and also NAV 2013 stores the length of the BLOB in the fist four bytes
// This is the rease why i read the datas not with SQLBytes
[b] long startIndex = 4;[/b] const int ChunkSize = 256;
while (true)
{
byte[] buffer = new byte[ChunkSize];
long retrievedBytes = myReader.GetBytes(0, startIndex, buffer, 0, ChunkSize);
outsqlstream.Write(buffer, 0, (int)retrievedBytes);
startIndex += retrievedBytes;
if (retrievedBytes != ChunkSize)
break;
}
MemoryStream outstream = new MemoryStream();
outsqlstream.Position = 0;
DeflateStream decompressedstream = new DeflateStream(outsqlstream, CompressionMode.Decompress);
decompressedstream.CopyTo(outstream);
outstream.Seek(0, SeekOrigin.Begin);
Encoding MyEnc = Encoding.UTF8;
BinaryReader BinReader = new BinaryReader(outstream, MyEnc);
retStr = BinReader.ReadString();
// Close streams don't wait for GAC
outsqlstream.Close();
outstream.Close();
decompressedstream.Close();
}
}
else
{
// record not found
return rmML.GetString("Error4");
}
myCon.Close();
return retStr;
}
catch (Exception ex)
{
// error while read
return(ex.Message);
}
}