Cause: DLL's that access databases require 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.
You could also have a dll outside the GAC that's trying to access some part of the SharePoint Object Model.
Fix:
There's a couple of ways to resolve this issue.
- Put you dll in the GAC. I don't like putting limited use web parts in there and managed code for InfoPath doesn't like it.
- 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.
Find in wss_mediumtrust.config:
<SecurityClass Name="SqlClientPermission" Description="System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
Copy and paste it in to the <SecurityClasses> node of wss_minimaltrust.config.
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. That about covers it. - You could also set the trust level to "wss_mediumtrust" or create a custom trust level. Google it...