Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.NET Crystal Report Printing 3

Status
Not open for further replies.

mgayb

Programmer
Oct 2, 2002
10
0
0
US
I have a report that successfully displays in the Crystal Viewer that comes built in with .NET within an .NET Web application. The viewer control resides on a webform.
I am trying to print the current report through code directly to the printer. I am consistently getting the following error:

Exception Details: CrystalDecisions.CrystalReports.Engine.InternalException:
Error in File C:\inetpub\ Request cancelled by the user.

Source Error:


Line 256: rptRepViewer.ReportSource = rp
Line 257: rp.PrintOptions.PrinterName = "\\twd-ps05\TWD-TEN-P302"
Line 258: rp.PrintToPrinter(1, True, 1, 1)
Line 259:

Line 258 is the one generating the error ? anyone with any ideas of what the problem might be. The printer name is correct.
 
Read this.
This will solve your problem...

Server side printing results in the report being generated on the Web Server and
being printed to a printer that is installed to the Web server.
Printing to a printer installed to the Web server requires that the process under
which ASP.NET is running have sufficient permissions to access Network
printers. In order to provide these permissions, changes to the account that the
ASPNET worker process runs under are necessary as well as changes to the
registry on the Web server.
By default, ASP.NET runs with the permissions of the local “machine”
(ASPNET account for the ASPNET worker process) account. In order to
achieve network printing through IIS (Internet Information Services), the
Framework should be run under the local SYSTEM account. To make this
change, it is necessary to edit the default configuration settings in the
Machine.config file. This file is located by default at:
C:\WINNT\Microsoft.NET\Framework\<VersionNumber>\CONFIGWhere <VersionNumber> is the version of the .NET Framework installed to the
computer. The account setting is contained within the <ProcessModel> tag of
this file. The default setting for the account is:
userName=&quot;machine&quot; password=&quot;AutoGenerate&quot;
This can be changed to:
userName=&quot;SYSTEM&quot; password=&quot;AutoGenerate&quot;

That's all...
 
i've tried to do those changes but it still gives me the error msg : Error in File C:\WINNT\TEMP\temp_8e96049b-b513-4b7c-93b7-f427552006e9.rpt: Request cancelled by the user


Can you tell if there is another trick?

Best regards

Manuel
 
I ended up not printing directly to the printer from the web server. Instead I made use of an article I got from Crystal Decisions Support on the options available to print from a web form using the .NET crystal viewer.

My solution was to stream the report programmatically to a temp PDF file and then on the client browser the report gets displayed as a pdf file. The Acrobat reader automatically gets embedded in the client browser which then allows for printing too.

Look at the code below:

The following VB (Visual Basic) code demonstrates exporting a report to PDF format and streaming it to the client’s browser to be displayed as a PDF document.

' Define Crystal Reports variables
Dim crReportDocument As ReportDocument
Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions

Dim Fname as String
' The following code can be placed directly after the call to InitializeComponent() in the form’s constructor, or inside of a Button_Click event where the button is used by the client to get a printable copy of the report.

CrReportDocument = New ReportDocument()
' The following line of code loads the sample report “Chart.rpt” that installs with Visual Studio .NET

CrReportDocument.Load (“C:\Program Files\Microsoft Visual Studio .NET\Crystal Reports\Samples\Reports\Feature Examples\Chart.rpt”)
Fname = “c:\exports\” & Session.SessionID.ToString & “.pdf”
CrDiskFileDestinationOptions = New DiskFileDestinationOptions()
CrDiskFileDestinationOptions.DiskFileName = Fname
CrExportOptions = crReportDocument.ExportOptions

With crExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
End With
CrReportDocument.Export()

'The following code writes the pdf file to the Client’s browser.
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = &quot;application/pdf&quot;
Response.WriteFile(Fname)
Response.Flush()
Response.Close()

'Delete the exported file from disk
System.IO.File.Delete(Fname)

When would I want to use this method for Printing?
Exporting a report to a printer-friendly format is useful to Web users who need the ability to print multiple page reports. You may wish to use the Web Forms viewer control to display the report on the client and provide a button on the form that will perform the export. This will
give the user the ability to utilize the interactivity (Drill-Down, etc.) of the Crystal report format within the viewer control and export the report to the more printer-friendly format at will.

This works well. Hope it answers your question.
 
How can I print a Crystal report document for .NET to a dot-matrix 9pin printer (OKI) and use the hardware settings made for the printer like condense and etc. Or possibly expotr to plain text fail
 
Hi fcp1,

even if you set the machine.config to use the SYSTEM account you still need to do the following:

When a printer is installed to a computer, the settings for this printer are stored in the registry under the HKEY_CURRENT_USER registry hive (Registry file). The IIS process will never use this registry hive since it always runs under the context of the local SYSTEM account and cannot be logged onto a server as a “Current User”. By default, the SYSTEM account does not have any printers set up in the registry. There are two Microsoft knowledge base articles, Q152451 and Q184291 that explain how to expose the printer settings to the System account. Both of these articles require editing the registry on the Web server and copying the printer settings from the HKEY_CURRENT_USER hive to the HKEY_USERS/.DEFAULT hive.

 
I had the same error message and the problem turned out to be the printer name.

I was using C# and I did not have the extra
i.e.

I had:

\\Crush\P1

instead of

\\\\Crush\\P1

Hope that helps someone out there.
 
oguzhan and juliaroberts suggestions worked great for me, but, it caused another issue in my web application. i was using a drop down list box to display all the installed printers on my web server and after i made the above changes I can no longer see them. does anybody know why that could be and how i can fix it? thanks in advance!

my code if it helps...

Private Sub GetPrinters()
Dim i As Integer
Dim pkInstalledPrinters As String

For i = 0 To PrinterSettings.InstalledPrinters.Count - 1
pkInstalledPrinters =
PrinterSettings.InstalledPrinters.Item(i)
ddlPrinters.Items.Add(pkInstalledPrinters)
Next
End Sub
 
Sorry to disturb all of you I am facing an unsolved problem
which I have already posted but nobody is repling i think one of you can help me because you already have done that.
I am giving the problem details below.
please any one help me! I am feeling helpless.
PROBLEM: Crystal Report in Web Application Fails to Log On to SQL Server
The information in this article applies to:
Microsoft Visual Studio .NET (2003), Professional Edition
Microsoft SQL Server 2000 (all editions) 8.0
Microsoft SQL Server 2000 (all editions) SP2


SYMPTOMS :
When you use SQL Server 2000 to obtain live data for a Crystal Report in a Visual Studio .NET Web application, the Crystal Report fails to log on to the database. This occurs even if you provide accurate credentials at design time. You receive the following error message in your Web browser:

Server Error in '/Crystal' Application.
-----------------------------------------------------------
Logon failed.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

CODE GENERATING ERROR :

Code Written in the crystalreportviewer1_load event
-----------------------------------------------------------------------------------------
Try
'for changing the data source at run time
'*********************************************
Dim strCon1 = &quot;Data Source=Mac05;Database=Immigration;User Id=sa;Password=;&quot;
Dim objCon1 As New SqlConnection(strCon1)
objCon1.Open()
Dim objAdapter As New SqlDataAdapter(&quot;select * from personaldetailsskilled&quot;, objCon1)
Dim objDs As New DataSet
objAdapter.Fill(objDs)

Dim objr As New sr1 'sr1.rpt is the report created previously

objr.SetDataSource(objDs)
'*****************************************
'code to specify connection for each table of the report
'*****************************************************

Dim crLogonInfo As TableLogOnInfo = New TableLogOnInfo

crLogonInfo.ConnectionInfo.ServerName = &quot;Mac05&quot;

crLogonInfo.ConnectionInfo.DatabaseName = &quot;Immigration&quot;

crLogonInfo.ConnectionInfo.UserID = &quot;sa&quot;

crLogonInfo.ConnectionInfo.Password = &quot;&quot;


Dim str As String = crLogonInfo.ConnectionInfo.ServerName

For Each myTable As Table In objr.Database.Tables

myTable.ApplyLogOnInfo(crLogonInfo)


Next



'*********************************************
'Code to bind the crystalreportviewer with the report
'**********************************************

Dim crTableLogoninfos = New TableLogOnInfos
crTableLogoninfos.Add(crLogonInfo)

CrystalReportViewer1.LogOnInfo = crTableLogoninfos
CrystalReportViewer1.ReportSource = objr
CrystalReportViewer1.DataBind()
'*******************************************************

Catch ex As Exception
Label1.Text = ex.Source & &quot; &quot; & ex.Message
End Try
-------------------------------------------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top