报表查看器 - 请求 SqlClientPermission 类型的权限失败 [英] Report Viewer - Request for the permission of type SqlClientPermission failed

查看:17
本文介绍了报表查看器 - 请求 SqlClientPermission 类型的权限失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地模式下使用 Visual Studio 2008 中的 ReportViewer 控件,并将对象作为数据源.我的类被映射到我的数据库中的数据表.在对象中,它根据需要加载相关对象.因此,在您尝试使用该属性之前,它会将引用保留为空,然后它会尝试自动从数据库中加载它.这些类使用 System.Data.SqlClient 命名空间.

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.

当我与 Windows 窗体应用程序中的对象交互时,一切都按预期进行.但是当我传递要用作报表数据源的对象并尝试自动加载相关对象时,它失败了.该代码创建了一个 SqlConnection 对象,当我对其调用 GetCommand() 时,抛出以下异常:

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

我已尝试搜索错误,但显示的所有结果都是针对在 SQL Server 或 ASP.Net 上运行的 CLR 程序集.在创建 SqlConnection 对象之前,我已经尝试在我的代码中添加以下调用(如搜索结果中所建议的那样),但它显然没有做任何事情:

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();

有什么想法吗?

推荐答案

我找到了解决方案.您将执行程序集(或具有足够权限的程序集)的 System.Security.Policy.Evidence 指定给 LocalReport 以在执行期间使用.

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);

这篇关于报表查看器 - 请求 SqlClientPermission 类型的权限失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆