Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Exporting to pdf from crystal reports stopped working

Posted on 2007-11-30
10
Medium Priority
?
2,108 Views
Last Modified: 2013-12-16
I have a piece of code that was working fine and is all of a sudden throwing the following error

{Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}

on this line -- rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat, context.Response, false, string.Empty);

rd is a ReportDocument.

this code was working fine. I do not know why it is throwing this error now! please help I need this solved!
public void ProcessRequest(HttpContext context)
    {
        ReportDocument rd = new ReportDocument();
        try
        {
            string path = context.Server.MapPath(ResolveUrl(GetReportPath()));
            rd.Load(path);
 
            if (GetIsODBC() == true)
            {
                string user = System.Configuration.ConfigurationManager.AppSettings["ReportUserName"];
                string password = System.Configuration.ConfigurationManager.AppSettings["ReportUserPassword"];
                rd.SetDatabaseLogon(user, password);
            }
            this.SetReportDataSources(context, rd); //set the data sources
 
            context.Response.Clear();
            rd.ExportToHttpResponse(ExportFormatType.PortableDocFormat, context.Response, false, string.Empty);
 
            context.Response.ContentType = "application/pdf";
            context.Response.Flush();
            context.Response.Close();
        }
        catch (Exception e)
        {
            context.Response.Clear();
            context.Response.Write(e.ToString());
            context.Response.Flush();
            context.Response.Close();
        }
        finally
        {
            rd.Close();
        }
    }

Open in new window

0
Comment
Question by:mattolan
10 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 20384466
Check out this article if u havent done it already
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=268544&SiteID=1
0
 
LVL 4

Expert Comment

by:habibb
ID: 20393817
se if there is any error in your formulas used in rpt file. try to reinstall pdf.
verify your schecm on which report is designed.
0
 
LVL 2

Author Comment

by:mattolan
ID: 20396078
ok, I found the problem, not sure why this was a problem though. crystal must do something wierd that I'm unaware of.

I deleted the catch section of the try catch finally and all is good

catch (Exception e)
{
     context.Response.Clear();
     context.Response.Write(e.ToString());
     context.Response.Flush();
     context.Response.Close();
}

Open in new window

0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 21

Expert Comment

by:surajguptha
ID: 20396136
wierd :)
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20396151
If u removed the catch block and if that fixed it, it means that it was going to the catch block before because of an exception and the catch which handled that exception threw your exception.
If you removed the catch, the original exception should have been thrown isnt it?
arghhh
0
 
LVL 2

Author Comment

by:mattolan
ID: 20396229
no, If I remove the catch, no exception is thrown. in fact the code works and I get the intended results!

arghhh is correct!
0
 
LVL 2

Accepted Solution

by:
mattolan earned 0 total points
ID: 20411757
it wasn't specifically the catch that was breaking it was the code inside the catch, crystal must have been messing with the Responce within its code (being a black box to me I don't really know what they are doing), and this must have been in conflict with my attempt to write to the reponce, because the below code on its own should not have caused me an issue
     context.Response.Clear();
     context.Response.Write(e.ToString());
     context.Response.Flush();
     context.Response.Close();

Open in new window

0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20411871
May be its messin the response up... Thanks for letting me know :)
0
 
LVL 1

Expert Comment

by:modus_operandi
ID: 20437971
Closed, 500 points refunded.
modus_operandi
EE Moderator
0

Featured Post

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month12 days, 16 hours left to enroll

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question