Printing exception message that says operation completed successfully

I'm a bit baffled by an exception that was thrown while trying to print:

Message:
The operation completed successfully

Stack Trace:
at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at CrystalDecisions.CrystalReports.Engine.FormatEngine.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN)

The message is not very helpful. Does anyone know what problem this could be pointing to?

[780 byte] By [chukky] at [2007-12-23]
# 1
The generic explanation for a www.thedailywtf.com

error message like that is Windows API call indicated failure but

GetLastError() returned 0. StandardPrintController.OnStartPrint

doesn't do a heck of a lot, other than calling the StartDoc() API call. If you're running this on Windows 98/ME, you'd get an exception message like that if StartDoc failed.

If you're pretty sure you've setup everything correctly, it is probably

a good idea to try your code with another printer driver. They

are not known for being particularly stable. If another printer

is OK, try upgrading the printer driver...

nobugz at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2

I ran into the same thing and I have found that if I run as a local admin on the box that is firing off the print job (even though it is to a network printer), I am able to print successfully, but if I run from a non-admin account (using the impersonation tag in the web.config file for running as both an admin and non-admin), then I get the same error. My thought was is that it is a security thing and my non-admin accounts just don't have the proper access, but I haven't been able to narrow down exactly what security is needed to print. nobugz, when you said "if you're pretty sure you've setup everything correctly", what exactly is everything? Are there certain security constraints? I have tried to even add my "user" as a Power User and still get this same error message. Since I can run fine when impersonating an admin, but fail when impersonating someone else, it doesn't seem like it is a printer driver issue.

Thanks

MichaelStokesbary at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3

I'm having the same problem.. an exception is thrown by OnStartPrint() with no an error message of "The operation completed successfully" returned. This happens for a Lexmark printer as well as a Xerox printer so I don't think its a driver problem.

I've tried running the app. as an enterprise admin and the problem did not go away.

I have no idea how to get .Net to print. Any suggestions?

Andrew.T at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 4
I was having exactly the same problem printing to a Generic / Text Only printer with XP SP1. I tried using SP2 drivers only but it didn't work. But SP2 fixes the problem.
BobHollman at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 5
Having not found a suitable solution to this problem online, I thought that I would post what I found as a workaround.

First, let me explain the environment. I have a windows service running on Windows Server 2003. Users execute code in the service under their own account using impersonation.

Doing a little research, it became apparent that administrators never received this error. I tried granting access to all directories and files to the spooler service. I also granted access to the printer. I even closely examined a filemon trace to try to find an access denied error to no avail. However, I found if I printed directly to the printer avoiding the spool service it printed correctly. This ended up being an acceptable solution for the application, partly because the printer in question was connected to a wireless print server that had it's own internal spooler, and partly because there is only a single user submitting print jobs.

If anyone can provide information on what the impersonated user might need access to to still be able to use the spooler I would appreciate it.

csanborn at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 6
I did see this error message while working on this thread. I didn't dig in to find the cause, I'm guessing the problem was caused by the thread not being in an STA and the printer driver trying to pop up a dialog. Try using the STAThread attribute or, when you print from a background thread, using Thread.SetApartmentState(). Just a guess though.
nobugz at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified