views:

263

answers:

3

Hi,

I have succesfully added a custom assembly, added it to the report using AddTrustedCodeModuleInCurrentAppDomain. I am executing the report in the current appdomin.

When I try to access SQL I get reporting services System.Data.SqlClient.SqlClientPermission failed. I have tried adding System.Data to the trusted assemblies as above but it doesn't help.

How do I ensure that this permission is present?

Regards Craig.

+1  A: 

From the error is sounds like your login credentials are being lost. What kind of authorization are you using?

If you are using Windows Authorization, you may be losing your "you"ness. Doesn't sound likely as you are calling in from the current appdomain. You may want to change the connection string to specify a username and password. If nothing else it should help in the debugging.

Good luck!

Craig
+1  A: 

Any luck with this?

I am using the ReportViewer control from Visual Studio 2008 in Local Mode with objects as the data source. My classes are mapped to data tables in my database. In the objects, it loads related objects as needed. So it leaves the reference null until you try to use the property, then it tries to load it from the database automatically. The classes use the System.Data.SqlClient namespace.

When I interact with the objects in my Windows Forms application, everything works as expected. But when I pass the object to be used as a Report Data Source and it tries to automatically load the related object, it fails. The code creates a SqlConnection object and when I call GetCommand() on it, the following exception is thrown:

[System.Security.SecurityException] {
"Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
} System.Security.SecurityException

I've tried searching for the error, but all the results that show up are for CLR assemblies running on a SQL Server or ASP.Net. I've tried adding the following call in my code (as suggested in the search results) before creating the SqlConnection objects, but it didn't apparently do anything:

System.Data.SqlClient.SqlClientPermission(System.Security.Permissions.PermissionState.Unrestricted).Assert();
CuppM
+1  A: 

I've found the solution. You specify System.Security.Policy.Evidence of you executing assembly (or one that has sufficient rights) to the LocalReport for use during execution.

reportViewer.LocalReport.ExecuteReportInCurrentAppDomain(System.Reflection.Assembly.GetExecutingAssembly().Evidence);
CuppM