Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem in reading images from sql server

Status
Not open for further replies.

gneti

Programmer
Feb 22, 2003
2
US
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.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top