Solved

Exporting to pdf from crystal reports stopped working

Posted on 2007-11-30
10
2,019 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 21

Expert Comment

by:surajguptha
Comment Utility
wierd :)
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 21

Expert Comment

by:surajguptha
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
May be its messin the response up... Thanks for letting me know :)
0
 
LVL 1

Expert Comment

by:modus_operandi
Comment Utility
Closed, 500 points refunded.
modus_operandi
EE Moderator
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now