Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / November 2007

Tip: Looking for answers? Try searching our database.

Retrieving image from SQL (C#) problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bjorn Sagbakken - 13 Nov 2007 06:23 GMT
This is kind of silly, but I just cannot figure out why:

In ASP.NET 2.0 I am retrieving images from a MS SQL server, and writing them
as binary to a separate page as the url for image controls, everything by
the book. I have been doing this a lot with VB. Now I am writing a new
application in C#, and the strange thng is this:

- it works well in debug mode
- but not on the published folder on the same server (localhost) - image
frames all have a cross in them
- a VB coded Image.aspx works well also on the published folder

Her is the C# code in the Image.aspx file::

....som init code...

SqlConnection con = new SqlConnection(init.con());
con.Open();
string strSQL = "SELECT img FROM photo where ID= " + ID;
SqlCommand cmd = new SqlCommand(strSQL, con);
imagebyte = (byte[])cmd.ExecuteScalar();
con.Close();
Response.Clear();
Response.ContentType = "image/jpeg";
Response.BinaryWrite(imagebyte);
Response.BufferOutput= true;

--> Why does this work in debug mode, and not on the published folder?

Bjorn
Eliyahu Goldin - 13 Nov 2007 08:56 GMT
If you set Response.BufferOutput= true; you will likely need to call
Response.Flush(); at some stage.

If the page is just serving images, there should not be any reason for
setting Response.BufferOutput= true.

Signature

Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

> This is kind of silly, but I just cannot figure out why:
>
[quoted text clipped - 26 lines]
>
> Bjorn
Bjorn Sagbakken - 13 Nov 2007 20:22 GMT
> If you set Response.BufferOutput= true; you will likely need to call
> Response.Flush(); at some stage.
>
> If the page is just serving images, there should not be any reason for
> setting Response.BufferOutput= true.

Well, I removed the Response.BufferOutput=true

and still the result is the same: in debug mode this works, but not when
running on the published folder.

Bjorn

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.