SmartPart error: sharepoint Request for the permission of type ‘System.Data.SqlClient.SqlClientPermission, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.

We recently upgradedf from SPS 2003 to MOSS 2007.  In the old portal, I had a couple of user controls running via the SmartPart.  After installing Return of SmartPart and adding the controls, I got an error every time I tried to search.  Way back in the dusty cobwebs, I remember troubleshooting this, and it was a permissions issue.  Checking in the Applications log, I found the following error: "sharepoint Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.".

Here's the fix:

Cause: Anything that access database from SP requires at least the WSS_Medium security policy in the web.config file. If you receive a security message from the web part, it's usually the trust element in the web.config file.

  1. Open wss_mediumtrust.config & wss_minimaltrust.config usually (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\config\) look in your web.config file for the exact path.
  2. Find in wss_mediumtrust.config: <SecurityClass Name="SqlClientPermission" Description="System.Data.SqlClient.SqlClientPermis sion, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
  3. Copy and paste it in to the <SecurityClasses> node of wss_minimaltrust.config.
  4. In the PermissionSet section of this configuration file, add the following: (Find in wss_mediumtrust.config) <IPermission class="SqlClientPermission" version="1" Unrestricted="true"/>.  Copy and paste it in to the a <PermissionSet> node of wss_minimaltrust.config.
  5. Save your wss_minimaltrust.config
  6. Reload your site, and try again

Presto!  Original source is