I'm trying to save a RasterImage to a SQL database via a MemoryStream with little success.  It appears that my examples in the documentation all save to a file, but if I'm overlooking something sorry for wasting your time.  Anyway, the first save works fine under most circumstances, but after saving another image I get the following exception message:
"Attempted to read or write protected memory.  This is often an indication that other memory is corrupt."
If I try to save again after the exception (which I catch), I get the following exception message:
"Invalid parameter passed."
I'm developing in C# with .NET 2.0 and LeadTools v. 15.  Below is the code where I load my SqlParameter object.  I start the RasterCodec engine at the beginning of a try and shut it down in the matching finally.  What am I doing wrong?
                            if (image.HighResolutionImage != null)
                            {
                                codecs = new RasterCodecs();
                                MemoryStream memoryStream = new MemoryStream();
                                codecs.Save(
                                    image.HighResolutionImage, memoryStream, RasterImageFormat.Cmp, 24);
                                byte[] blob = memoryStream.GetBuffer();
                                SqlParameter parameter = new SqlParameter(
                                    "@picture",
                                    SqlDbType.Image,
                                    blob.Length,
                                    ParameterDirection.Input,
                                    false, 0, 0, null,
                                    DataRowVersion.Current,
                                    blob);
                                sqlCmd.Parameters.Add(parameter);
                                memoryStream.Close();
                                codecs.Dispose();
                            }
                            if (image.LowResolutionImage != null)
                            {
                                codecs = new RasterCodecs();
                                MemoryStream memoryStream = new MemoryStream();
                                codecs.Save(
                                    image.LowResolutionImage, memoryStream, RasterImageFormat.Cmp, 24, 1, 1, 1, CodecsSavePageMode.Replace);
                                byte[] blob = memoryStream.GetBuffer();
                                SqlParameter parameter = new SqlParameter(
                                    "@thumbnail",
                                    SqlDbType.Image,
                                    blob.Length,
                                    ParameterDirection.Input,
                                    false, 0, 0, null,
                                    DataRowVersion.Current,
                                    blob);
                                sqlCmd.Parameters.Add(parameter);
                                memoryStream.Close();
                                codecs.Dispose();
                            }