I'm getting a rather frustrating error from Business Intelligence Development Studio (Visual Studio 2008). I have a report that contains 4 sub-reports, these sub-reports may or may not contain data, and as such their HIDDEN property is controlled by an expression:
=IIF(ReportItems![SOME TEXT BOX].Value = 0, TRUE, FALSE)
The contents of [SOME TEXT BOX] is the number of rows returned by the stored procedure for its respective sub-report, thus if the value is 0, then the rectangle containing the sub-report is set to HIDDEN = TRUE.
This works for 3 of the 4 sub-reports, but for some reason, one of them causes this error:
The hidden expression for [RECTANGLE CONTAINING SUB-REPORT] contains an error:
Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed
Some Googling reveals that this is (clearly) to do with access permissions, but most people seem to be experiencing the error in relation to MS Sharepoint, and the solutions do not seem applicable.
Any help would be most appreciated!
Brian
Edit: This only occurs when 'ReportItems![SOME TEXT BOX].Value = 0' returns TRUE, i.e. there are no rows.
OK, so I've found the real cause of this problem; Microsoft, and their unhelpful error messages! But seriously I was getting this error because I was passing a NULL value.
Assuming you've read my initial question, the dataset that was getting the NULL was the one that populates [SOME TEXT BOX], but the NULL was not in the field that populates [SOME TEXT BOX]. A bit round the houses but I've got there in the end!
I found another cause of this problem, when you're migrating your code from .NET Framework 4.0 to 4.5: permissions. Now, the permission in the ReportViewer by default are more restricted.
To fix. Do the following in your code.
When instancing Report Viewer, set the unrestricted mode:
var myReport = new ReportViewer();
System.Security.PermissionSet permissionReport = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
myReport.LocalReport.SetBasePermissionsForSandboxAppDomain(permissionReport);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With