Getting this error: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
- int id = int.Parse((sender as LinkButton).CommandArgument);
- byte[] bytes;
- string fileName, contentType;
- string constr = ConfigurationManager.ConnectionStrings["JKPSC"].ConnectionString;
- try
- {
- using (SqlConnection con = new SqlConnection(constr))
- {
- using (SqlCommand cmd = new SqlCommand())
- {
- cmd.CommandText = "select id, pdfType, pdfdata, regNo from tbl_Doc where id=@Id";
- cmd.Parameters.AddWithValue("@Id", id);
- cmd.Connection = con;
- con.Open();
- using (SqlDataReader sdr = cmd.ExecuteReader())
- {
- sdr.Read();
- bytes = (byte[])sdr["pdfdata"];
-
- fileName = sdr["pdfType"].ToString() + sdr["regNo"].ToString() + ".pdf";
- }
- con.Close();
- }
- }
- Response.Clear();
- Response.Buffer = true;
- Response.Charset = "";
- Response.Cache.SetCacheability(HttpCacheability.NoCache);
- Response.ContentType = "application/pdf";
- Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
- Response.BinaryWrite(bytes);
- Response.Flush();
- Response.Close();
- Response.End();
-
-
- }
- catch (Exception ex)
- {
- throw;
- }
How to solve this error