Error in Printing the document using SQL CLR Stored Procedure

  • 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.

  • 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.

  • 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.

  • 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

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply