TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rahul Sharma
NA
194
14.2k
Error while downloading pdf stored in database
Sep 18 2019 7:04 AM
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
Reply
Answers (
3
)
Delete not working
Call image upload web service ASP.NET-android using Retrofit