This is a migrated thread and some comments may be shown as answers.

Best practice for adding dynamic PictureBox

5 Answers 652 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
AkAlan
Top achievements
Rank 2
AkAlan asked on 04 Oct 2013, 08:46 PM
I have a report that has a PictureBox on it which I am using for an employee signature. I store the signature in the SQL server as a varbinary(max). The employee signature will be different for every report and is returned in the SqlDataSource for the report. I recently started getting a ""Parameter Not Valid" exception when rendering the report as a pdf and had to reboot the IIS server to get the report to render again. I must either be doing something wrong or not using the best practice for this scenario.  Here is how I am importing the bmp signature to the table in SQL server:

UPDATE [HR_Employees]
SET  EmployeeSignature = (SELECT BulkColumn FROM OPENROWSET(
            Bulk 'C:\Signatures\Justin.bmp', SINGLE_BLOB)AS BLOB)
            WHERE EmployeeNumber = '99999'

Here is how I am rendering the report to pdf:
public ActionResult PrintPoReport(string id)
       {
           var irs = new InstanceReportSource();
           irs.ReportDocument = new LogisticsReports.PoHeader();
           irs.Parameters.Add(new Parameter("PoID", id));
           Telerik.Reporting.Processing.ReportProcessor rp = new Telerik.Reporting.Processing.ReportProcessor();
           Telerik.Reporting.Processing.RenderingResult result = rp.RenderReport("PDF", irs, null);
           byte[] contents = result.DocumentBytes;
           return File(contents, "application/pdf", "P0 #" + id + ".pdf");
 
       }

I think it is the signature block causing the issue but I could be wrong. Any suggestions as to how to properly add a bmp file to a report dynamically?

5 Answers, 1 is accepted

Sort by
0
Hadib Ahmabi
Top achievements
Rank 1
answered on 09 Oct 2013, 12:37 PM
I don't see the code where you dynamically add the picture. 
First you can try to remove the PictureBox and see if that really is the problem. 
Additionally, if your pictures are stored locally, then you can pass the full filename using a ReportParameter. 
You should also be able to see more info about the exception - stack trace, etc.. (you can hook up to the Error event of the ReportProcessor). 
0
AkAlan
Top achievements
Rank 2
answered on 09 Oct 2013, 04:16 PM
Habid, As I said in my post, the picture is stored in the SQL Server and returned to the report in the SqlDataSource. Depending on the record being returned, a different image will be returned with every report. The report is already in production and I can't remove the picture. It is a picture of a users signature and needs to be on the report. All I can do is wait for it to fail again and reboot the server agian. When I do a search on "Parameter Not Valid" I see a number of posts that seem to indicate it is an issue with retrieving an image from a database like I am doing. Here is a perfect example of a site that addresses the exact exception I am getting http://www.codeproject.com/Tips/465950/Why-do-I-get-a-Parameter-is-not-valid-exception-wh
So lets just say for the sake of argument that loading an image from the database into the report is my issue. What would be a better way to load the image. I could store each users signature locally and name it with users EmployeeID which is part of the report data and dynamically point to the image in the C# code that calls the report and send it a s a parameter. Can you provide a quick code example of how to pass the file name to the report as you had mentioned? How would I then render the image in the report? Thanks for any help.
0
Stef
Telerik team
answered on 11 Oct 2013, 03:04 PM
Hello Alan,

The PictureBox.Value property can be set through binding to a field, report parameter, user fucntion or other valid expression from which can be created an image object.

If you need further help, please send us the exception stack trace, details how you set the image to the PictureBox item, and if the issue is reproducible without the image or with other report. Also specify the used Telerik Reporting version.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
AkAlan
Top achievements
Rank 2
answered on 22 Oct 2013, 05:47 PM
Hi Stef, After properly working for a few days,  the exception is back, here is the Stack Trace:

[ArgumentException: Parameter is not valid.]
   System.Drawing.Image.get_RawFormat() +1624719
   Telerik.Reporting.PictureBox.set_Value(Object value) +145
   LogisticsReports.PoHeader.InitializeComponent() +59796
   ArctecLogisticsWebFiles.Controllers.LogisticsToolsController.PrintPoReport(String id) +64
   lambda_method(Closure , ControllerBase , Object[] ) +127
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +264
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +129
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +826106
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +314
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +825328
   System.Web.Mvc.Controller.ExecuteCore() +159
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375


I republished the application after removing the picture box but the exception remains. I'm going to have to re-boot the server to clear the exception. This is a difficult issue to resolve because it works on my development machine, it works on my development IIS server and it works until failure on my production machine. Can you see from this exception what the issue coupld possibly be?
0
IvanY
Telerik team
answered on 25 Oct 2013, 03:40 PM
Hi Alan,

In general the error you are getting means that GDI+ cannot create an image from the buffer that is supplied. This issue is usually caused by the image itself, so there is a chance that a particular image (or images) in your database are causing this. Additionally you can check for a similar problem this forum thread - check out rh's answer, you might be facing the same issue.

Finally in order to help you more adequately we will need some more information and it will be best if you can open a support ticket and send us there a sample project that exhibits the issue. However please note that since most probably the issue is caused by the image itself it will be crucial for us to have that image (stored in a database) otherwise most probably we will not be able to reproduce the issue locally.

Regards,
IvanY
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

Tags
General Discussions
Asked by
AkAlan
Top achievements
Rank 2
Answers by
Hadib Ahmabi
Top achievements
Rank 1
AkAlan
Top achievements
Rank 2
Stef
Telerik team
IvanY
Telerik team
Share this question
or