title: Error while Image loading from database
body: <p>I am using a generic handler for loading Image from data bases. Its work fine when when I hardcode the <code>ImageID</code> in the query string when call handler. But it's giving error of different type when I dynamically pass value from query string (from datatable):</p>
  
  <blockquote>
    <p>ExecuteReader requires an open and available Connection. The connection's current state is open.</p>
  </blockquote>
  
  <p>OR</p>
  
  <blockquote>
    <p>Invalid operation. The connection is closed.</p>
  </blockquote>
  
  <p>Here is the code of handler</p>
  
  <pre><code>public void ProcessRequest(HttpContext context)
  {
      Int64 id = Convert.ToInt64(context.Request.QueryString["adid"]);
      dt = GetRecpDetailsByID(id);
  
      if (dt.Rows.Count &gt; 0)
      {
          //context.Response.ContentType = "image/jpeg";
          context.Response.BinaryWrite((byte[])dt.Rows[0][2]);
      }
  }
  
  public DataTable GetRecpDetailsByID(Int64 reid)
  {
      try
      {
          obj_DB.Open();
          obj_sqlcmd = new SqlCommand("GetRecpDetailsByID", obj_DB.GetDBConnection());
          obj_sqlcmd.CommandType = CommandType.StoredProcedure;
  
          obj_sqlcmd.Parameters.Add(new SqlParameter("@rid", reid));
          obj_sqlda = new SqlDataAdapter();
  
          obj_dt = new DataTable();
          obj_sqlda.SelectCommand = obj_sqlcmd;
          obj_sqlda.Fill(obj_dt);
  
          return obj_dt;
      }
      finally
      {
          obj_DB.Close();
      }
  }
  </code></pre>
  
  <p>And here is the HTML and server-side code on ASPX page of call handler</p>
  
  <pre><code>  &lt;img id="img2" alt="Image" runat="server" src='&lt;%#"ImageReqHAndler.ashx?adid="+Eval("Reid")%&gt;' width="179" height="148" /&gt;
  </code></pre>