|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 9:44 AM
Points: 78,
Visits: 251
|
|
Hi,
I am trying to print the byte array which I am receiving from reporting service's render method. I have used PrintDocument class in my CLR stored proc. I have also addded the system.drawing assembly. here is my code
PrintDocument printDoc = new System.Drawing.Printing.PrintDocument();
public String PrintImage(string printerDestination, byte[] image) { try {
string status = ""; _documentToPrint = image; printDoc.PrinterSettings.PrinterName = @"\\printserver\HR Canon iR5070"; //printerDestination;
//PrintingPermission b = new PrintingPermission(PrintingPermissionLevel.DefaultPrinting);
strErrMsg = "Setting Print Controller->"; PrintController standard = new StandardPrintController(); printDoc.PrintController = standard; //wire event //printDoc.PrintPage += new PrintPageEventHandler(this.printDoc_PrintPage); printDoc.PrintPage+=new PrintPageEventHandler(printDoc_PrintPage); strErrMsg = strErrMsg + "Calling Print Method | " + printDoc.PrinterSettings.PrinterName + "|"; printDoc.Print(); //status = "File Printed"; return strErrMsg; } catch (Exception ex) { _documentToPrintCurrentPage = 0; // strErrMsg = strErrMsg + ex.Message; strErrMsg = strErrMsg + ex.Message + "->" + ex.InnerException.Message + "->" + _documentToPrint.Length.ToString() + "-> Print Image Method"; //status = strErrMsg; // strErrMsg = ""; } }
private void printDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { strErrMsg = strErrMsg + "inside printDoc_PrintPage | "; MemoryStream ms = new MemoryStream(_documentToPrint); strErrMsg += "--lenght:" + ms.Length.ToString() +"."; Bitmap bm = (Bitmap)Bitmap.FromStream(ms); // Throwing an exception at this line Graphics g = e.Graphics; try { int pagesFound = bm.GetFrameCount(FrameDimension.Page);
if (pagesFound > 0) { bm.SelectActiveFrame(FrameDimension.Page, _documentToPrintCurrentPage); _documentToPrintCurrentPage++; if (_documentToPrintCurrentPage >= pagesFound) { e.HasMorePages = false; _documentToPrintCurrentPage = 0; } else e.HasMorePages = true;
g.DrawImageUnscaled(bm, 0, 0); } } catch (Exception ex) { _documentToPrintCurrentPage = 0; throw ex; } }
Any ideas?
Thanks.
Thanks.
Gunjan.
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 10:47 AM
Points: 37,729,
Visits: 29,990
|
|
Um..
The CLR proc runs on the server, within the database server. Where do you think it's going to print to?
What exception is it throwing?
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 9:44 AM
Points: 78,
Visits: 251
|
|
It should print it to network printer. and the exception is
System.NullReferenceException: Object reference not set to an instance of an object. System.NullReferenceException:at StoredProcedures.BRCOffer_Process(String DataBaseName) .
Thanks.
Gunjan.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Sunday, May 12, 2013 4:26 PM
Points: 1,696,
Visits: 1,742
|
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Saturday, May 04, 2013 11:13 AM
Points: 9,855,
Visits: 9,374
|
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Saturday, May 04, 2013 11:13 AM
Points: 9,855,
Visits: 9,374
|
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 9:44 AM
Points: 78,
Visits: 251
|
|
I have already done that.
Same error
Thanks.
Gunjan.
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 9:44 AM
Points: 78,
Visits: 251
|
|
I am only trying to print it out.
and this line throwing an exception
Bitmap bm = (Bitmap)Bitmap.FromStream(ms);
Thanks.
Gunjan.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Sunday, May 12, 2013 4:26 PM
Points: 1,696,
Visits: 1,742
|
|
I am not in a position to check immediately but I would venture a guess that the HPA's on the Assembly may preclude it from use in SQL completely. At best ( or worst depending on which side of the SQLCLR fence you sit on) you will only be able to use part of the classes in the Assembly.
SQL Server is a database server, not an application, image processing, or print server. If it does have to do with validating/manipulating/reading/updating data it has no business in SQL server. You just can't convince .NET developers of this for some reason. Is there a DBA anywhere involved with this project/development?
Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008 My Blog | Twitter | MVP Profile Training | Consulting | Become a SQLskills Insider Troubleshooting SQL Server: A Guide for Accidental DBAs
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 10:47 AM
Points: 37,729,
Visits: 29,990
|
|
Jonathan Kehayias (2/3/2009) If it does not have to do with validating/manipulating/reading/updating data it has no business in SQL server.
I think you left a not out of that statement
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|