Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Error in Printing the document using SQL CLR Stored Procedure


Error in Printing the document using SQL CLR Stored Procedure

Author
Message
Gunjan
Gunjan
SSC-Enthusiastic
SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)

Group: General Forum Members
Points: 120 Visits: 309
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.
Gunjan
Gunjan
SSC-Enthusiastic
SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)

Group: General Forum Members
Points: 120 Visits: 309
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...Smile
Let me see I will keep posting the question or solution for this post.

Thanks

Thanks.

Gunjan.
Gunjan
Gunjan
SSC-Enthusiastic
SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)SSC-Enthusiastic (120 reputation)

Group: General Forum Members
Points: 120 Visits: 309
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.
armin.bahamin
armin.bahamin
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search