Error while printing crystal report, with that exception message “No printers are installed”

断了今生、忘了曾经 提交于 2019-12-11 14:52:59

问题


I got an exception with message "No printers are installed." while printing a report for depolyed release of our website.
I use _rptDocument.PrintToPrinter(1, false, 0, 0); to print a report.

I got that exception, even I've more than one printer installed on my machine. Also, I don't get that exception while development, everything while development is going fine.

I used "Publish Web Site" and "Web Project Deployment" options to publish/deploy website, but I got the same result.

Any suggestions?

Edit

Sample Code

DataSet dsResult = null;
rptDocument = new ReportDocument();
rptDocument.Load(Server.MapPath("WINGR0040.rpt"));

// Fetch report data.
...

rptDocument.SetDataSource(dsResult);

// Print report.
rptDocument.PrintToPrinter(1, false, 0, 0);

回答1:


I would really export the report to PDF so the user prints at their desktop printer. However maybe the Print Spooler Service is stopped on the iis server so crytsal is confused.




回答2:


Have you added a printer on the Web server under the user account that site runs under?

Have you tried setting the printer name first?

Report.PrintOptions.PrinterName = printerName;

If your site runs under an account e.g DOMAIN\WebService you need to ensure that this user account has a default printer.

You could also try setting the printer name like this:

Report.PrintOptions.PrinterName = this.printDocument1.PrinterSettings.PrinterName;

This will get the default printer.

This article may help you get this working.

EDIT:

This article on MSDN describes how printing can be acheived using Crystal Reports and ASP.NET. If you are not implementing either of these solutions then I don't think you will be able to print client side.

The .cab file mentioned in the MSDN link can be found here:

Visual Studio 2005 or Visual Studio 2008

Without you posting further code and more detail as to how you are generating the report I don't I am going to be able to fully answer your question.

Thanks




回答3:


I dont found a way to print by client-side.

There go how works to me by server-side:

on Page_Load i got this:

foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
    DropDownList1.Items.Add(printer);
}

Now on button_click:

var dsTela = (DataSet)Session["dsTela"];

var cr = new ReportDocument();

var rpt = Request.QueryString["nomeRel"];
cr.Load(Server.MapPath("~/Crystal/" + rpt));

    //----------Crystal Reports---------------//

    // carrega o reltório
cr.SetDataSource(dsTela);

System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();

printerSettings.PrinterName = DropDownList1.SelectedValue;

cr.PrintToPrinter(printerSettings, new PageSettings(), false);

//this one works for me

If your printer don`t show in your server-side, try this one:

Source: (https://support2.microsoft.com/default.aspx?scid=kb;en-us;184291)

To enable IIS to enumerate the network printers by using the SYSTEM account, follow these steps.

Note If the process is running under the Network Service account, explicit permissions to the newly created registry are required.

  1. Make sure that you are currently logged in to the server as a user who has the desired network printers installed.
  2. Start Registry Editor.
  3. Click the following key: HKEY_CURRENT_USER\Printers\Connections
  4. On the Registry menu, click Export Registry File.
  5. In the File Name box, type c:\printconns.reg.
  6. To open the printconns.reg file in Notepad, click Start, click Run, type Notepad printconns.reg in the Open box, and then click OK.
  7. Replace the text HKEY_CURRENT_USER with the text HKEY_USERS.DEFAULT.
  8. Save the file.
  9. To import the file into the registry, double-click the file in Windows Explorer.
  10. Restart the Print Spooler service.


来源:https://stackoverflow.com/questions/2620780/error-while-printing-crystal-report-with-that-exception-message-no-printers-ar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!