Solved

Export report to PDF in ASP.NET - Logon Failed.

Posted on 2003-11-10
8
18,519 Views
Last Modified: 2007-12-19
Hi

I have been all over the web looking for an answer to my problem and none of the solutions seem to be exactly right for my situation.

Scenario:
ASP.NET page using C#
I have a Crystal report that connects to an XML file (That is the Database Type is "ADO.NET (XML)".

The .aspx file is essentially empty (as created by VS.NET2003).
In the codebehind page, I have the following code:

private void Page_Load(object sender, System.EventArgs e)
{
      ReportDocument crReportDocument = new ReportDocument();
      ExportOptions crExportOptions = new ExportOptions();
      DiskFileDestinationOptions crDiskFileDestinationOptions = new DiskFileDestinationOptions();
      String Fname = "";

      crReportDocument.Load(Server.MapPat("PhoneList.rpt"),CrystalDecisions.Shared.OpenReportMethod.OpenReportByTempCopy);
      Fname = "c:\\TEMP\\" + Session.SessionID.ToString() + ".pdf";
      crDiskFileDestinationOptions.DiskFileName = Fname;
      crExportOptions = crReportDocument.ExportOptions;
            
      crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
      crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
      crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

      crReportDocument.Export();

      Response.ClearContent();
      Response.ClearHeaders();
      Response.ContentType = "application/pdf";
      Response.WriteFile(Fname);
      Response.Flush();
      Response.Close();

      System.IO.File.Delete(Fname);
}

This is the only code in the ASPX page (codebehind).

When I run this page on my dev machine, everything looks good.

When create a setup projet and deploy it to my server, I get the good old "Logon failed" error:

Exception Details: CrystalDecisions.CrystalReports.Engine.LogOnException: Logon failed.

Things I have tried:

1.  Changing the machine.config ProcessModel username and restarting IIS
2.  Making sure that the setup projet has the following merge modules
      - Crystal_Database_Access2003.msm
      - Crystal_Database_Access2003_enu.msm
      - Crystal_Managed2003.msm
      - Crystal_regwiz2003.msm (including the key)
      - VC_User_CRT71_RTL_x86_---.msm
      - VC_User_STL71_RTL_x86_---.msm
4.  Giving ASPNET read/write access to the app folder as well as the C:\Temp folder used to export the PDF.

Many solutions talk about adding proper credentials using code similar to this:

TableLogOnInfo crLogonInfo = new TableLogOnInfo();
crLogonInfo = crReportDocument.Database.Tables[0].LogOnInfo;
crLogonInfo.ConnectionInfo.ServerName = "myServer";
crLogonInfo.ConnectionInfo.UserID = "sa";
crLogonInfo.ConnectionInfo.Password = "sa";
crLogonInfo.ConnectionInfo.DatabaseName = "?";
crReportDocument.Database.Tables[0].ApplyLogOnInfo(crLogonInfo);

However, since I am using an XML file for my datasource, I do not know what to use for username and password, as well as Server and DatabaseName.

Since this works fine on my local workstation I'm guessing that files are still missing in the setup... any help would be greatly appreciated!

Michel
0
Comment
Question by:MichelBord
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 9719231
What version and edition of Crystal?

What edition of VS.Net 2003?

mlmcc
0
 

Author Comment

by:MichelBord
ID: 9722176
Hmm, sorry about that.  I did mean to include those details. :)

Visual Studio.Net 2003 - Professional edition
  Microsoft Development Environment 2003 - v7.1.3088
  Microsoft .NET Framework 1.1 - v.1.1.4322 (both on client and server)
Crystal Reports for Visual Studio .NET (bundled w/ VS.NET2003 Pro)

Thanks

Michel

0
 

Author Comment

by:MichelBord
ID: 9929966
Can anyone help with this... we are still stuck!
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 100

Expert Comment

by:mlmcc
ID: 9934635
0
 

Author Comment

by:MichelBord
ID: 9958489
Thanks mlmcc,

 Unfortunately, this doesn't help.  The sample did lead me to try using the Report Object instead but that still has the same issue.

I have seen tried a few other options.  The following is my most recent code... the big difference is that I use ExportToStream so I don't need to write the PDF file to disk first.  This removes a variable.

ReportDocument crReportDocument = new ReportDocument();
crReportDocument.Load(Server.MapPath("BIPhoneList.rpt"));
System.IO.Stream st;
st = crReportDocument.ExportToStream(ExportFormatType.PortableDocFormat);

Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/PDF";
byte[] b = new byte[st.Length];
st.Read(b,0,(int) st.Length);
Response.BinaryWrite(b);
Response.Flush();
Response.Close();
0
 

Accepted Solution

by:
MichelBord earned 0 total points
ID: 9958926
This issue has now been resolved.  I emailed Crystal Help support and they quickly replied back saying that the error was probably due to the fact that the XML file was in a different location on the server... at first I didn't believe it... I thought "the file is in the same folder as the code in both cases"... but the absolute path is indeed different!  Turns out, the RPT was hard-coding the absolute path to the XML file so it couldn't find it on the server.

The solution was the add the following lines after the crReportDocument.Load.

DataSet dataSet = new DataSet();
dataSet.ReadXml("c:\\Tel.xml");
crReportDocument.SetDataSource(dataSet);

Of course, now I'll go ahead and move the XML file to a better location, but I'll be able to point the report to it in a more visible and obvious way.

Thanks to those who attempted to help.

Michel
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 9961397
Submit a request to PAQ this question in the Community Support TA

mlmcc
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

738 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