title: Retrieving image from database to a data grid in c#
body: <p>I saved the image into the database in binary format. I get an error when i am trying to retrieve it. The error says "The connection name 'ConnectionString' was not found in the applications configuration or the connection string is empty." This is my code, what am i doing wrong?? </p>
  
  <pre><code>//Code for generic handler
  
  &lt;%@ WebHandler Language="C#" Class="Handler" %&gt;
  
  using System;
  using System.Web;
  using System.Configuration;
  using System.Data.SqlClient;
  public class Handler : IHttpHandler {
  
      public void ProcessRequest (HttpContext context) {
      SqlConnection con = new SqlConnection();
      con.ConnectionString = ConfigurationManager.ConnectionStrings["Data Source=ACER-   
                               PC\\SQLEXPRESS;Initial Catalog=imageDemo;Integrated 
                               Security=True"].ConnectionString;
  
      SqlCommand cmd = new SqlCommand();
      cmd.CommandText = "Select ImageName,Image from image" + " where ID =@ID";
      cmd.CommandType = System.Data.CommandType.Text;
      cmd.Connection = con;
      SqlParameter ImageID = new SqlParameter("@ID", System.Data.SqlDbType.Int);
      ImageID.Value = context.Request.QueryString["ID"];
      cmd.Parameters.Add(ImageID);
      con.Open();
      SqlDataReader dReader = cmd.ExecuteReader();
      dReader.Read();
      context.Response.BinaryWrite((byte[])dReader["Image"]);
      dReader.Close();
      con.Close();
  }
  
      //Code for datagrid
  
      &lt;asp:GridView ID="GridView1" runat="server" 
            AutoGenerateColumns="False" DataKeyNames="ID"
            DataSourceID="SqlDataSource1"&gt;
      &lt;Columns&gt;
      &lt;asp:BoundField DataField="ID" HeaderText="ID" 
              InsertVisible="False" ReadOnly="True"
                             SortExpression="ID" /&gt;
      &lt;asp:BoundField DataField="ImageName" HeaderText="ImageName" 
                             SortExpression="ImageName" /&gt;
      &lt;asp:TemplateField HeaderText="Image"&gt;
      &lt;ItemTemplate&gt;
      &lt;asp:Image ID="Image1" runat="server" 
         ImageUrl='&lt;%# "Handler.ashx?ID=" + Eval("ID")%&gt;'/&gt;
      &lt;/ItemTemplate&gt;
      &lt;/asp:TemplateField&gt;
      &lt;/Columns&gt;
      &lt;/asp:GridView&gt;
      &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;"
      SelectCommand="SELECT [ID], [ImageName], [Image] 
            FROM [image]"&gt;&lt;/asp:SqlDataSource&gt;
  </code></pre>