Link to home
Start Free TrialLog in
Avatar of mattolan
mattolanFlag for Canada

asked on

Exporting to pdf from crystal reports stopped working

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

Avatar of surajguptha
surajguptha
Flag of United States of America image

Check out this article if u havent done it already
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=268544&SiteID=1
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.
Avatar of mattolan

ASKER

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

wierd :)
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
no, If I remove the catch, no exception is thrown. in fact the code works and I get the intended results!

arghhh is correct!
ASKER CERTIFIED SOLUTION
Avatar of mattolan
mattolan
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
May be its messin the response up... Thanks for letting me know :)
Avatar of modus_operandi
modus_operandi

Closed, 500 points refunded.
modus_operandi
EE Moderator