Can't prepare report in a W32 Service

FAlvaradoFAlvarado US/Mexico
edited 8:35PM in FastReport 4.0
I'm developing a Service application using DXE5, ADOQueries and Fast-Reports 4 Pro to generate a graph and export it to PDF file to be displayed in a WEB application. A second thread is called from within the service main thread.

The problem I'm experimenting is that the report is not prepared and it's closed! The resulting PDF file is empty, no graph and no bands
see bellow: ****** Error Can't prepare report *********
If I run the resulting query and prepare a report in an desktop application it runs Ok.
Any idea of what I'm doing wrong?

Best Regards

Francisco Alvarado

The report thread
uses
  WinApi.Windows, WinApi.Messages, System.SysUtils, System.Classes,
  frxChart, frxOLE, frxClass, frxExportHTML, ComObj, frxExportPDF, frxDBSet, Data.DB, Data.Win.ADODB, WinApi.ActiveX;

  // in the execute procedure:
  if Assigned(ComObj.CoInitializeEx) then
    CoInitializeEx(nil, COINIT_MULTITHREADED)
  else
    CoInitialize(nil);
  // Do NOT free on termination - The Service frees the Thread
  FreeOnTerminate := False;

  // Create Components
  ADOConnection1 := TADOConnection.Create(nil);
  ADOConnection1.Connected := False;
  ADOConnection1.ConnectionString := Connection;
  ADOQuery1 := TADOQuery.Create(nil);
  frxReport1 := TfrxReport.Create(nil);
  frxReport1.EngineOptions.SilentMode := True;
  frxReport1.EngineOptions.EnableThreadSafe := True;
  frxReport1.EngineOptions.UseFileCache := false;
  frxReport1.ShowProgress := False;
  frxReport1.Engine.OnRunDialog := ShowReportDialog;
  frxChartObject1 := TfrxChartObject.Create(nil);
  frxDBDataset1 := TfrxDBDataset.Create(nil);
  // create PDF export object  for test
  frxPDFExport1 := TfrxPDFExport.Create(nil);
  frxPDFExport1.ShowDialog := False;
  frxPDFExport1.ShowProgress := False;
  // Create HTML export object
  frxHTMLExport1 := TfrxHTMLExport.Create(nil);
  frxHTMLExport1.ShowDialog := False;
  frxHTMLExport1.ShowProgress := False;
  // Set components properties
  ADOConnection1.ConnectionString := Connection;
  ADOConnection1.LoginPrompt := False;
  ADOQuery1.Connection := ADOConnection1;
  ADOConnection1.Connected := True;
  // Prepare the query
  ADOQuery1.Close;
  ADOQuery1.Prepared := False;
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add('SELECT * FROM RepTable');
  ADOQuery1.Prepared := True;
  ADOQuery1.Open;
  WriteLog('Srvc.log',  IntToStr(ADOQuery1.RecordCount) + ' Records' +#13+ ADOQuery1.SQL.Text);
  // The SQL is fine, it runs Ok and there are 7 rows in result; the query is NOT empty
  if not ADOQuery1.Eof then
  begin
	if frxReport1.LoadFromFile('C:\Reports\ReportTest.fr3') then	// Report loads Ok
          begin
            frxDBDataset1.DataSet := ADOQuery1;
            frxReport1.DataSet := frxDBDataset1;     			// just in case  
            frxPDFExport1.FileName := 'Report.pdf';
            try								
              if frxReport1.PrepareReport(True) then			// or frxReport1.PrepareReport(false) same behaviour
                begin
                  if frxReport1.Export(frxPDFExport1) then
                    // Ok
                  else
                    WriteLog('Srvc.log', 'Error Exporting Report');
                end
              else
                 WriteLog('Srvc.log', 'Error Preparing Report');	// ****** Error Can't prepare report *********
            except
              on E: Exception do
                WriteLog('Srvc.log', 'Error preparing' + frxReport1.ReportOptions.Name + ' for ' + Name +#13+ E.Message);
		// NO Exception here
            end;
	    WriteLog('Srvc.log', frxReport1.ReportOptions.Name);	// the name of the report is blank
            frxReport1.Clear;
          end
        else
          WriteLog('Srvc.log', 'Can''t load report ' + 'ReportTest.fr3');
  end;

Comments

  • gpigpi
    edited 8:35PM
    Attach small demo project based on FRDemo database
  • edited 8:35PM
    I have the same problem on a Win 2008 R2 Server.

    Works perfectly on a Win 2003 Server and Win 7.

    TIA
  • edited 8:35PM
    Works perfectly on a Win 2003 Server and Win 7......!!!!
  • edited 8:35PM
    tazy wrote: »
    Works perfectly on a Win 2003 Server and Win 7......!!!!

    Okay! [img]style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" /> My application works as expected... Still don't have an answer to my problem...[/img]
  • edited 8:35PM
    Does anyone have PDF export working on win 2008 r2 server?

    I still can't get it working. ..

    Anyone from FRIDAY watching this forum?

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.