Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Reading images from SQL Server

Author  Topic 

jani
Starting Member

2 Posts

Posted - 2004-08-18 : 12:54:15
I am trying to retrieve images from SQL server and display them on the client’s browser. Images in the SQL server are imported from MS Access 2002

I found the following code that mentions about removing the OLE Header for Northwind Database. I tried using the same logic to retrieve images from the database that I imported and got an error “Invalid parameter” when trying to run the program



private void DisplayImages ()
{

string connectionString = "workstation id=\"GA33611-PDD\";user id=sa;password=dufas;data source=\"GA33611-PDD" +
"\";initial catalog=northwind";

SqlConnection cn = new SqlConnection(connectionString);

SqlCommand cmd = new SqlCommand(cmdText, cn);

MemoryStream ms = new MemoryStream();

// 78 is the size of the OLE header for Northwind images.
// There's no header in PUBS as PUBS
// just contains the raw image bits.
int offset = 78;

cn.Open();
byte [] img = (byte[]) cmd.ExecuteScalar();
ms.Write(img, offset, img.Length-offset);
cn.Close();

Bitmap bmp = null;
bmp = new Bitmap(ms);
Response.ContentType = "image/gif";
bmp.Save(Response.OutputStream, ImageFormat.Gif);
ms.Close();


}


As I think may be I need to remove that OLE header in my database. Are there any ways to find out the size of this header.

Any help in this regard is greatly appreciated.



Thank you

ehorn
Master Smack Fu Yak Hacker

1632 Posts

Posted - 2004-08-18 : 15:01:56
Have a look on the web as there are many example of how to do this:
Here is a few.

http://www.dotnetbips.com/displayarticle.aspx?id=60
http://www.dotnetspider.com/Technology/KBPages/558.aspx
Go to Top of Page
   

- Advertisement -