Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / August 2004

Tip: Looking for answers? Try searching our database.

Crystal Report from an XML Webservice

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
FeveZ - 15 Aug 2004 20:15 GMT
I've been stuck on a problem now for ages and i'm about ready to pack my
project in because of it lol.

OK here is my scenario.

I have an existing Crystal Report, which I have added to my solution and
published it as a webservice. This report takes it data from an SQL server on
another machine.

The user will have a windows form in a little app i'm writing where it has a
web reference to this report... it will show the report from this Web Service
in the crystal report view control.

I set the report datasource to this web service... however I keep getting
the database logon screen whenever I run the report... if I enter the correct
password it runs fine... but my problem is I dont want this sodding box to
come up all the time!

Ive seen examples of other users problems where they are to set the logon
details for every table but I cannot seem to do this myself as I cant get to
the actual crystal report object from the web service to change the database
table logon bits.

Am I making sense here? Someone please help ths is really sapping my will to
live...

Thanks in advance.

FeveZ
FeveZ - 16 Aug 2004 12:37 GMT
Can somebody please shed some light on this as to what im doing wrong?

None of my posts ever get answered :-(

Thanks :-)
Fev
Tim Gallivan - 16 Aug 2004 20:20 GMT
FeveZ,

You can easily stream your report as a PDF straight to the browser, too.
Looks much
more professional than the ugly crystal control on the screen. Here's how to
do what you want (in a nutshell):

1) In your webservice, set your report to get its data from a dataset
2) Have your data layer retrieve the report data in the form of a DataSet
3) Set the reports DataSource (.SetDataSource) to the DataSet in 3)
4) Export the report to a stream (ExportToStream), and convert it to a array
of bytes
5) Return the byte array to the calling web page, which can
Response.BinaryWrite it to the client browser
6) Wipe hands on pants and repeat!

Here's sample code:
yada yada yada: it's always nice to see the USINGS!!
using System;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;

using Microsoft.ApplicationBlocks.ExceptionManagement;

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

 [WebMethod]
 public byte[] GetDataForDTReport(int fiscalYearId,int programId,int
languageId)
 {
  // Declaration section
  ReportDs report = new ReportDs(); //our data service
  DataSet reportData = new DataSet();
  System.IO.Stream dataStream;
  byte[] pdfReport = new byte[1];
  ExportRequestContext requestCtx = new ExportRequestContext();

  // Create an instance of your report class
  DTReport repDoc = new DTReport();
  bool dataReturned = true;

  try
  {
   // Validation section
   // Call the data services for the report
   reportData =
report.GetDataForDTReport(fiscalYearId,programId,languageId);

   //If tables are returned
   if(reportData.Tables.Count > 0)
   {
    //If at least one table has no rows
    foreach(DataTable table in reportData.Tables)
    {
     if(table.Rows.Count == 0)
     {
      dataReturned = false;
      break;
     }
    }
    if(dataReturned)
    {
     // Set the data source for the report
     repDoc.SetDataSource(reportData);
     repDoc.ExportOptions.ExportFormatType =
ExportFormatType.PortableDocFormat;
     repDoc.ExportOptions.FormatOptions =  new PdfRtfWordFormatOptions();
     requestCtx.ExportInfo = repDoc.ExportOptions;
     dataStream = repDoc.FormatEngine.ExportToStream(requestCtx);

     // Convert the data stream with the pdf report into an array
     pdfReport = new byte[dataStream.Length];
     dataStream.Read(pdfReport,0,(int)dataStream.Length);
     dataStream.Close();
    }
   }
   return pdfReport;
  }
  catch(Exception ex)
  {
   // Wrap exception and rethrow
   throw new BaseApplicationException("Web Service Exception", ex);
  }
  finally
  {
   // Cleanup code
   reportData = null;
   dataStream = null;
   pdfReport = null;
  }
 }

Signature

Tim Gallivan
I know I'm a great teacher because when I give a lesson, the person never
comes back.

> I've been stuck on a problem now for ages and i'm about ready to pack my
> project in because of it lol.
[quoted text clipped - 25 lines]
>
> FeveZ
FeveZ - 17 Aug 2004 12:13 GMT
Sweet thanks...  Cant test it right now because im away from my dev kit :-D

I'll let you know how it goes :D

Thanks again :-)

Fev

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.