Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Error in Printing the document using SQL CLR Stored Procedure Expand / Collapse
Author
Message
Posted Thursday, January 29, 2009 7:56 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Yesterday @ 8:25 AM
Points: 78, Visits: 281
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.
Post #645943
Posted Thursday, January 29, 2009 8:17 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Yesterday @ 8:25 AM
Points: 78, Visits: 281
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.
Post #645972
Posted Thursday, January 29, 2009 9:06 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Yesterday @ 8:25 AM
Points: 78, Visits: 281
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.
Post #646050
Posted Wednesday, March 14, 2012 8:35 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, December 18, 2013 12:40 AM
Points: 2, Visits: 18
Dear Sir,
Have you solved your last problem in sending print job to a printer from SQL Server Procedure?
could you please inform me about any likely solution?

Thanks
Armin
Post #1266780
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse