Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello. for showing photo in my site. i am using Handler(.NET 3.5) to read from DB a and show it in DataList. But when i uploaded the site photos are shown slow.
Please look at the site:

http://omed-ltd.com/[^]
omed-ltd.com

and the code that i am using:
<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data.SqlClient;
public class Handler : IHttpHandler {

    SqlConnection myConnection;
    SqlCommand cmd;
    
    public Handler()
    {
        myConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["myDB"].ConnectionString);
        cmd = new SqlCommand("", myConnection);
        myConnection.Open();
    }
    public void ProcessRequest (HttpContext context) {
        try
        {
            string sql = "Select TPImage,id,Image_Type from TProduct where Id=@Id";
            cmd.CommandText = sql;
            cmd.Parameters.Add("@Id", System.Data.SqlDbType.Int).Value =    context.Request.QueryString["Id"];
            cmd.Prepare();
            SqlDataReader dr = cmd.ExecuteReader();
            dr.Read();
            context.Response.ContentType = dr["Image_Type"].ToString();
            
            context.Response.BinaryWrite((byte[])dr["TPImage"]);
            //باید برای عکس یکی از این فایل ساخته شود تا که بتونی هر عکس رو جدا لود کرد.
            dr.Close();
            myConnection.Close();
        }
        catch (Exception ex)
        {
            //System.Windows.Forms.MessageBox.Show(ex.Message);
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

Thank you.
Posted
Updated 20-Jan-13 7:58am
v2

1 solution

1. Consider generating thumbnails for previews. On a link above to display preview about 100x100 pixels size you are spooling 1M+ pictures.

2. Imagine your website channel load if it becomes popular

3.Strictly saying, it is not recommended to store pictures of a such big size in the database.

4. consider supporting http caching as well.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900