none
ms-sql image data from mysql blob field RRS feed

  • Question

  • hi people

     

    I have imported "blob" data from mysql to an ms-sql 2000 "Image" field, using ms-  sql enterprise manager. However my c# image veiwer does not work on the imported blob data (it does work on data I add to ms-sql via my web application).

     

    Is there any way I can check that the blob data creates a valid image? If anyone has any ideas of how I can debug the data coming out that would be great. Or perhaps someone can point me to somewhere I can get some help?

     

    any pointers are much appreciated!

     

    Greg

     

    p.s here is the code for my Image Viewer!

     

    <%@ WebHandler Language="C#" Class="imageViewer" %>

    using System;

    using System.Web;

    using System.IO;

     

    public class imageViewer : IHttpHandler { public void ProcessRequest (HttpContext context)

     

    {

    product prod = new product(context.Request.QueryString["code"].ToString());
      prod.load();

    Stream stream = null;
      context.Response.ContentType = "image/jpeg";

    context.Response.Cache.SetCacheability(HttpCacheability.Public);
      context.Response.BufferOutput = false;

    int buffersize = 1024;
      byte[] buffer = new byte[buffersize];

    stream = new MemoryStream(prod.ImageThumb); int count = stream.Read(buffer,      0, buffersize);while (count > 0)
      {

     context.Response.OutputStream.Write(buffer, 0, count);

     count = stream.Read(buffer, 0, buffersize);

    }

    }

     

    public bool IsReusable {
    get {

    return false;
    }

    }

    }

     


     

    Tuesday, June 19, 2007 9:26 AM

Answers

  • Put the stream.read method within the while loop. Now you only read the first 1024 bytes from the MemoryStream and the image is probably larger than that. Also it's easier to use a buffer from the memory itself. You can get it with the MemoryStream.GetBuffer() method.
    Tuesday, June 19, 2007 10:56 PM

All replies

  • Me thinks you have the wrong forum. This is for SSIS.
    Tuesday, June 19, 2007 9:38 AM
  • Moving to the Visual C# General forum.
    Tuesday, June 19, 2007 1:00 PM
  • Put the stream.read method within the while loop. Now you only read the first 1024 bytes from the MemoryStream and the image is probably larger than that. Also it's easier to use a buffer from the memory itself. You can get it with the MemoryStream.GetBuffer() method.
    Tuesday, June 19, 2007 10:56 PM