读取数据库 System.Data.SqlClient.SqlClientPermission 解决方法

问题场景

在写一个读写数据库的WinForm组件,当该组件在web页面上引用的时候,出现错误:

 

 

请求“System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”类型的权限已失败。”

 

运行环境为:  IIS5.1 + ASP.NET4.0 + WinXP

 

 

解决方法

参考如下文档,解决我的问题

 

The error 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failedgenerally occurs when try to run the stored procedure.

This error often occurs when try to run the Stored Procedure from the web application.

Possible Reason
1. Not enough security permission for the stored Procedure
2. Anything that access database from SP requires at least the WSS_Medium security policy in the web.config file.
3. If the security message is from the web part, it's usually the trust element in the web.config file.

How to Fix?

1. Open wss_mediumtrust.config & wss_minimaltrust.config files
2. The normal path is (C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/12/config/)
3. We can find the exact path in web.config file 
4. Find in the wss_mediumtrust.config File: 

Name="SqlClientPermission"
Description="System.Data.SqlClient.SqlClientPermis sion, System.Data,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>


5. Copy and paste it in to the node of wss_minimaltrust.config file.
6. In the PermissionSet section of this configuration file, add the following:
Find in wss_mediumtrust.config: class="SqlClientPermission" version="1" Unrestricted="true"/>
Copy and paste it in to the a node of wss_minimaltrust.config.

 


7. Goto Control Panel - Administrative Tools
8. Goto .NET Framework configuration settings

9. 设置步骤如下:

    a.  Expand the runtime security policy.

     b.  expand machine

     c.  expand code groups

     d.  right click all_code

     e.  Click on properties

     f.  Click on permission tab 
     g.  Set Modified nothing to Full Trust
 


 

总结:

        不知道是版本的问题还是什么问题,对于上面的解决方案中的,步骤1-5中的文件wss_mediumtrust.config & wss_minimaltrust.config 我都没有找到,只执行了步骤7-9过程。另外配置的过程中,本机器有两个.net版本1.1和2.0的版本,我两个都设置了一下就OK了,有空再确认一下是1.1还是2.0版本造成的。

 

 

参考:

http://hi.baidu.com/gzqsd/blog/item/3ca125fad1b1c22a4e4aea68.html

http://www.dotnetspider.com/resources/29741-Sql-Error-System-Data-SqlClient-SqlClientPermission-System-Data-Version-Culture-neutr.aspx

http://hi.baidu.com/%D2%BB%B5%E3%C7%E7/blog/item/ac65af254f747420d4074289.html

 

 


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值