|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Monday, March 08, 2010 2:03 PM
Points: 61,
Visits: 148
|
|
Hi,
I am trying to print the Image using SQL CLR Stored procedure. I have used the PrintDocument class of .NET. In that I have used the object of System.Drawing class. To access the Assembly I have created the assembly of System.Drawing in my sql server database.
But when I am executing the stored procedure it is throwing the following error:
A .NET Framework error occurred during execution of user-defined routine or aggregate "BRCOffer_ProcessBRC_Email": System.IO.FileLoadException: Could not load file or assembly 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Assembly in host store has a different signature than assembly in GAC. (Exception from HRESULT: 0x80131050) System.IO.FileLoadException: at StoredProcedures.BRCOffer_ProcessBRC_Email() .
Can I print the image from SQL CLR Stored Procedure or not?
Please help.
Thanks.
Thanks.
Gunjan.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Monday, March 08, 2010 2:03 PM
Points: 61,
Visits: 148
|
|
Hi All,
I resolved that error by creating the assembly
CREATE ASSEMBLY [System.Drawing]FROM 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll'WITH PERMISSION_SET = UNSAFE
Initially I was creating the assembly from my network path, that's why it was throwing an error.
Now trying to print the image, still that is pending...:) Let me see I will keep posting the question or solution for this post.
Thanks
Thanks.
Gunjan.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Monday, March 08, 2010 2:03 PM
Points: 61,
Visits: 148
|
|
Hi,
Now the error comes while calling the Print Method is
Value cannot be null. Parameter name: type.
Here is my code for printing.
private static byte[] _documentToPrint; private static int _documentToPrintCurrentPage = 0; private static string strErrMsg = "";
public String PrintImage(string printerDestination, out string status, byte[] image) { try {
// FaxId = MyFaxID; _documentToPrint = image; PrintDocument printDoc = new System.Drawing.Printing.PrintDocument(); printDoc.PrinterSettings.PrinterName = @"\\printserver\HR Canon iR5070"; //printerDestination;
//wire event printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage); strErrMsg = "Calling Print Method | " + printDoc.PrinterSettings.PrinterName + "|"; printDoc.Print(); //Exception occurs here status = "File Printed"; return status; } catch (Exception ex) { _documentToPrintCurrentPage = 0; strErrMsg = strErrMsg + ex.Message + "->" + _documentToPrint.Length.ToString() + "-> Print Image Method"; status = strErrMsg; strErrMsg = ""; return status;
} }
private void printDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { strErrMsg = strErrMsg + "inside printDoc_PrintPage | "; MemoryStream ms = new MemoryStream(_documentToPrint); Bitmap bm = (Bitmap)Bitmap.FromStream(ms); 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; strErrMsg = strErrMsg + ex.Message + "-->" + _documentToPrint.Length.ToString() + " -> printDoc_PrintPage Method"; throw ex; } }
What could be the issue?
Thanks.
Gunjan.
|
|
|
|