打印水晶报表时出错,并显示异常消息“未安装打印机”

发布于 2024-08-28 16:41:34 字数 547 浏览 3 评论 0原文

我收到异常消息“未安装打印机”。同时打印我们网站的 depolyed 发布报告。
我使用 _rptDocument.PrintToPrinter(1, false, 0, 0); 打印报告。

我遇到了这个例外,即使我的机器上安装了不止一台打印机。 另外,我在开发过程中没有遇到这种异常,开发过程中一切都很顺利。

我使用“发布网站”和“Web 项目部署”选项来发布/部署网站,但得到了相同的结果。

有什么建议吗?

编辑

示例代码

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);

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);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

稳稳的幸福 2024-09-04 16:41:34

我确实会将报告导出为 PDF,以便用户在桌面打印机上进行打印。但是,iis 服务器上的打印后台处理程序服务可能已停止,因此 crytsal 会感到困惑。

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.

∝单色的世界 2024-09-04 16:41:34

您是否已在网站运行所用的用户帐户下的 Web 服务器上添加了打印机?

您是否尝试过先设置打印机名称?

Report.PrintOptions.PrinterName = printerName;

如果您的站点在 DOMAIN\WebService 等帐户下运行,您需要确保该用户帐户具有默认打印机。

您还可以尝试像这样设置打印机名称:

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

这将获得默认打印机。

这篇文章可能会帮助您实现此目的。

编辑:

MSDN 上的这篇文章描述了如何打印可以使用 Crystal Reports 和 ASP.NET 来实现。如果您没有实施这些解决方案中的任何一个,那么我认为您将无法打印客户端。

MSDN 链接中提到的 .cab 文件可以在这里找到:

Visual Studio 2005
或者
Visual Studio 2008

无需发布更多代码和有关如何生成的更多详细信息报告我不知道我能够完全回答你的问题。

谢谢

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

一袭水袖舞倾城 2024-09-04 16:41:34

我没有找到客户端打印的方法。

服务器端对我来说是如何工作的:

在 Page_Load 上,我得到了这个:

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

现在在 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);

//这个对我有用

如果您的打印机没有在服务器端显示,请尝试这个:

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

要使 IIS 能够使用 SYSTEM 帐户枚举网络打印机,请按照下列步骤操作。

注意 如果该进程在网络服务帐户下运行,则需要对新创建的注册表具有显式权限。

  1. 确保您当前以安装了所需网络打印机的用户身份登录到服务器。
  2. 启动注册表编辑器。
  3. 单击以下键:
    HKEY_CURRENT_USER\Printers\Connections
  4. 在“注册表”菜单上,单击“导出注册表文件”。
  5. 在“文件名”框中,键入 c:\printconns.reg。
  6. 若要在记事本中打开 printconns.reg 文件,请单击“开始”,单击“运行”,在“打开”框中键入 Notepad printconns.reg,然后单击“确定”。
  7. 将文本 HKEY_CURRENT_USER 替换为文本 HKEY_USERS.DEFAULT。
  8. 保存文件。
  9. 要将文件导入注册表,请在 Windows 资源管理器中双击该文件。
  10. 重新启动后台打印程序服务。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文