webparts & sqlclientpermission

A

António Pinho

Hi,

I have a big problem with an webpart/assembly. i'm trying to connect to sql
server but i get the error "Request for the permission of type
System.Data.SqlClient.SqlClientPermission, System.Data, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.". i've searched for
it and can't find a clear answer. but one thing i'm sure: permissions. if i
change the trust level in the web.config of the sharepoint portal that i
created to full, everything works fine.

can someone help me?

TIA


code of the assembly, web.config, wss_minimaltrust_Custom.config

webpart/assembly

protected override void RenderWebPart(HtmlTextWriter output)
{
String strConn =
"server=myserver;database=mydb;uid=myuser;password=mypwd;";
SqlClientPermission permission = new
SqlClientPermission(PermissionState.Unrestricted);

try
{
permission.Demand();
permission.Assert();

SqlConnection Conn = new SqlConnection(strConn);
Conn.Open();
Conn.Close();
Conn.Dispose();
}
catch (Exception ex)
{
output.Write(ex.Message);
}
finally
{
output.Write(" the end");
};
}


web.config

<configuration>
<configSections>
<sectionGroup name="SharePoint">
<section name="SafeControls"
type="Microsoft.SharePoint.ApplicationRuntime.SafeControlsConfigurationHandl
er, Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" />
<section name="RuntimeFilter"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="WebPartLimits"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="WebPartCache"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="WebPartWorkItem"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="WebPartControls"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="SafeMode"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="OnlineLibrary"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>
</configSections>
<SharePoint>
<SafeMode MaxControls="50" CallStack="false" />
<WebPartLimits MaxZoneParts="50" PropertySize="1048576" />
<WebPartCache Storage="CacheObject" />
<WebPartWorkItem Timeout="7000" />
<WebPartControls
DatasheetControlGuid="65BCBEE4-7728-41a0-97BE-14E1CAE36AAE" />
<!--
SafeControl Attributes:
Assembly="[Assembly]" - The .NET assembly in which the control is
contained. This attribute can also contain version, culture, and public key
token information.
Namespace="[Namespace]" - The .NET namespace in which the control
is defined.
TypeName="[Typename]" - The .NET class name of the control. You
can type an asterisk (*) wildcard character to indicate all TypeNames in a
Namespace.
Safe="[True|False]" - Specifies whether a Web Part or Web Form
Control is safe and can be displayed on a Web Parts Page. This attribute is
True by default.
-->
<SafeControls>
<SafeControl Assembly="System.Web, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="System.Web.UI.WebControls" TypeName="*" Safe="True" />
<SafeControl Assembly="System.Web, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="System.Web.UI.HtmlControls" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.WebPartPages" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.WebControls" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.ApplicationPages" TypeName="*" Safe="True"
/>
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.SoapServer" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.Meetings" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint.Portal, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.Portal.WebControls" TypeName="*" />
<SafeControl Assembly="Microsoft.SharePoint.Portal, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.Portal.WebControls.Alerts" TypeName="*" />
<SafeControl Assembly="WebPartLibrary1, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=819bece51b5870e7"
Namespace="WebPartLibrary1" TypeName="*" Safe="True" />
</SafeControls>
<!--<OnlineLibrary Url="http://r.office.microsoft.com/r/hlidAwsGallery"
/>-->
<RuntimeFilter Assembly="Microsoft.SharePoint.Portal, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Class="Microsoft.SharePoint.Portal.Audience.AudienceManager"
BuilderURL="audience_chooser.aspx" />
</SharePoint>
<system.web>
<securityPolicy>
<trustLevel name="WSS_Medium" policyFile="C:\Program Files\Common
Files\Microsoft Shared\Web Server
Extensions\60\config\wss_mediumtrust.config" />
<trustLevel name="WSS_Minimal" policyFile="C:\Program Files\Common
Files\Microsoft Shared\Web Server
Extensions\60\config\wss_minimaltrust.config" />
<trustLevel name="WSS_Minimal_Custom" policyFile="C:\Program
Files\Common Files\Microsoft Shared\Web Server
Extensions\60\config\wss_minimaltrust_Custom.config" />
</securityPolicy>
<httpHandlers>
<add verb="*" path="/_vti_bin/*.aspx"
type="System.Web.UI.PageHandlerFactory, System.Web, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add verb="*" path="*.aspx"
type="Microsoft.SharePoint.ApplicationRuntime.SharePointHandlerFactory,
Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" />
</httpHandlers>
<customErrors mode="On" />
<httpRuntime maxRequestLength="51200" />
<authentication mode="Windows" />
<authorization>
<allow users="*" />
</authorization>



wss_minimaltrust_Custom.config

<configuration>
<mscorlib>
<security>
<policy>
<PolicyLevel version="1">
<SecurityClasses>
<SecurityClass Name="AllMembershipCondition"
Description="System.Security.Policy.AllMembershipCondition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="AspNetHostingPermission"
Description="System.Web.AspNetHostingPermission, System, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="FirstMatchCodeGroup"
Description="System.Security.Policy.FirstMatchCodeGroup, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="NamedPermissionSet"
Description="System.Security.NamedPermissionSet"/>
<SecurityClass Name="SecurityPermission"
Description="System.Security.Permissions.SecurityPermission, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="StrongNameMembershipCondition"
Description="System.Security.Policy.StrongNameMembershipCondition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="UnionCodeGroup"
Description="System.Security.Policy.UnionCodeGroup, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="UrlMembershipCondition"
Description="System.Security.Policy.UrlMembershipCondition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="WebPartPermission"
Description="Microsoft.SharePoint.Security.WebPartPermission,
Microsoft.SharePoint.Security, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c"/>
<SecurityClass Name="ZoneMembershipCondition"
Description="System.Security.Policy.ZoneMembershipCondition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SqlClientPermission"
Description="System.Data.SqlClient.SqlClientPermission, System.Data,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</SecurityClasses>
<NamedPermissionSets>
<PermissionSet
class="NamedPermissionSet"
version="1"
Unrestricted="true"
Name="FullTrust"
Description="Allows full access to all
resources"
/>
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="Nothing"
Description="Denies all resources, including
the right to execute"
/>
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="ASP.Net">
<IPermission
class="AspNetHostingPermission"
version="1"
Level="Minimal"
/>
<IPermission
class="SecurityPermission"
version="1"
Flags="Execution"
/>
<IPermission class="WebPartPermission"
version="1"
Connections="True"
/>
</PermissionSet>
<PermissionSet class="NamedPermissionSet"
version="1" Name="WebPartLibrary1PermissionSet">
<IPermission class="AspNetHostingPermission" version="1" Level="Medium"
/>
<IPermission class="SecurityPermission" version="1" Flags="Assertion,
Execution, ControlThread, ControlPrincipal, RemotingConfiguration,
UnmanagedCode" />
<IPermission class="WebPartPermission" version="1" Connections="True" />
<IPermission class="SqlClientPermission" version="1"
AllowBlankPassword="False" />
</PermissionSet>
</NamedPermissionSets>
<CodeGroup
class="FirstMatchCodeGroup"
version="1"
PermissionSetName="Nothing">
<IMembershipCondition
class="AllMembershipCondition"
version="1"
/>
<CodeGroup
class="UnionCodeGroup" version="1"
PermissionSetName="WebPartLibrary1PermissionSet">
<IMembershipCondition
class="StrongNameMembershipCondition"
version="1"

PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000
100B791C96EBFCD6E192C8998945A628B4E3F466EC49BFA4C812BCE256F6CB8BB734D2EAC64F
6D0C3CFC52135C321B21C12476512369A0D5BCAD0ED80587C2655A34C6811D353219C680E955
E47871281302233AFF8A0D4009F59299B3867DF61823E36FEAA55A5DB0ABDEE2EC39745068C5
8BF32E13F2709EC147890FD33B847D5" />
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="ASP.Net">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="$AppDirUrl$/*"
/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="$CodeGen$/*"
/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust">
<IMembershipCondition
class="UrlMembershipCondition"
Url="$Gac$/*"
version="1"
/>
</CodeGroup>
<CodeGroup class="UnionCodeGroup" version="1"
PermissionSetName="Nothing">
<IMembershipCondition
class="ZoneMembershipCondition"
version="1"
Zone="MyComputer" />
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Microsoft_Strong_Name"
Description="This code group grants code
signed with the Microsoft strong name full trust. ">
<IMembershipCondition

class="StrongNameMembershipCondition"
version="1"

PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000
10007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD
9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E82
1C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D2
61C8A12436518206DC093344D5AD293"
/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Ecma_Strong_Name"
Description="This code group grants code
signed with the ECMA strong name full trust. ">
<IMembershipCondition

class="StrongNameMembershipCondition"
version="1"

PublicKeyBlob="00000000000000000400000000000000"
/>
</CodeGroup>
</CodeGroup>
</CodeGroup>
</PolicyLevel>
</policy>
</security>
</mscorlib>
</configuration>
 
M

Mihai Durcau

Try to add in web.config the SQL Assembly in the SAFE section:

<SafeControls>
<SafeControl Assembly="System.Data.SqlClient, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="System.Web.UI.WebControls" TypeName="*" Safe="True" />
of course IISReset - don't forget where you are :)
MD

António Pinho said:
Hi,

I have a big problem with an webpart/assembly. i'm trying to connect to sql
server but i get the error "Request for the permission of type
System.Data.SqlClient.SqlClientPermission, System.Data, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.". i've searched for
it and can't find a clear answer. but one thing i'm sure: permissions. if i
change the trust level in the web.config of the sharepoint portal that i
created to full, everything works fine.

can someone help me?

TIA


code of the assembly, web.config, wss_minimaltrust_Custom.config

webpart/assembly

protected override void RenderWebPart(HtmlTextWriter output)
{
String strConn =
"server=myserver;database=mydb;uid=myuser;password=mypwd;";
SqlClientPermission permission = new
SqlClientPermission(PermissionState.Unrestricted);

try
{
permission.Demand();
permission.Assert();

SqlConnection Conn = new SqlConnection(strConn);
Conn.Open();
Conn.Close();
Conn.Dispose();
}
catch (Exception ex)
{
output.Write(ex.Message);
}
finally
{
output.Write(" the end");
};
}


web.config

<configuration>
<configSections>
<sectionGroup name="SharePoint">
<section name="SafeControls"
type="Microsoft.SharePoint.ApplicationRuntime.SafeControlsConfigurationHandl
er, Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" />
<section name="RuntimeFilter"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="WebPartLimits"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="WebPartCache"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="WebPartWorkItem"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="WebPartControls"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="SafeMode"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="OnlineLibrary"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>
</configSections>
<SharePoint>
<SafeMode MaxControls="50" CallStack="false" />
<WebPartLimits MaxZoneParts="50" PropertySize="1048576" />
<WebPartCache Storage="CacheObject" />
<WebPartWorkItem Timeout="7000" />
<WebPartControls
DatasheetControlGuid="65BCBEE4-7728-41a0-97BE-14E1CAE36AAE" />
<!--
SafeControl Attributes:
Assembly="[Assembly]" - The .NET assembly in which the control is
contained. This attribute can also contain version, culture, and public key
token information.
Namespace="[Namespace]" - The .NET namespace in which the control
is defined.
TypeName="[Typename]" - The .NET class name of the control. You
can type an asterisk (*) wildcard character to indicate all TypeNames in a
Namespace.
Safe="[True|False]" - Specifies whether a Web Part or Web Form
Control is safe and can be displayed on a Web Parts Page. This attribute is
True by default.
-->
<SafeControls>
<SafeControl Assembly="System.Web, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="System.Web.UI.WebControls" TypeName="*" Safe="True" />
<SafeControl Assembly="System.Web, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="System.Web.UI.HtmlControls" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.WebPartPages" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.WebControls" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.ApplicationPages" TypeName="*" Safe="True"
/>
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.SoapServer" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.Meetings" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint.Portal, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.Portal.WebControls" TypeName="*" />
<SafeControl Assembly="Microsoft.SharePoint.Portal, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.Portal.WebControls.Alerts" TypeName="*" />
<SafeControl Assembly="WebPartLibrary1, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=819bece51b5870e7"
Namespace="WebPartLibrary1" TypeName="*" Safe="True" />
</SafeControls>
<!--<OnlineLibrary Url="http://r.office.microsoft.com/r/hlidAwsGallery"
/>-->
<RuntimeFilter Assembly="Microsoft.SharePoint.Portal, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Class="Microsoft.SharePoint.Portal.Audience.AudienceManager"
BuilderURL="audience_chooser.aspx" />
</SharePoint>
<system.web>
<securityPolicy>
<trustLevel name="WSS_Medium" policyFile="C:\Program Files\Common
Files\Microsoft Shared\Web Server
Extensions\60\config\wss_mediumtrust.config" />
<trustLevel name="WSS_Minimal" policyFile="C:\Program Files\Common
Files\Microsoft Shared\Web Server
Extensions\60\config\wss_minimaltrust.config" />
<trustLevel name="WSS_Minimal_Custom" policyFile="C:\Program
Files\Common Files\Microsoft Shared\Web Server
Extensions\60\config\wss_minimaltrust_Custom.config" />
</securityPolicy>
<httpHandlers>
<add verb="*" path="/_vti_bin/*.aspx"
type="System.Web.UI.PageHandlerFactory, System.Web, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add verb="*" path="*.aspx"
type="Microsoft.SharePoint.ApplicationRuntime.SharePointHandlerFactory,
Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" />
</httpHandlers>
<customErrors mode="On" />
<httpRuntime maxRequestLength="51200" />
<authentication mode="Windows" />
<authorization>
<allow users="*" />
</authorization>



wss_minimaltrust_Custom.config

<configuration>
<mscorlib>
<security>
<policy>
<PolicyLevel version="1">
<SecurityClasses>
<SecurityClass Name="AllMembershipCondition"
Description="System.Security.Policy.AllMembershipCondition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="AspNetHostingPermission"
Description="System.Web.AspNetHostingPermission, System, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="FirstMatchCodeGroup"
Description="System.Security.Policy.FirstMatchCodeGroup, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="NamedPermissionSet"
Description="System.Security.NamedPermissionSet"/>
<SecurityClass Name="SecurityPermission"
Description="System.Security.Permissions.SecurityPermission, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="StrongNameMembershipCondition"
Description="System.Security.Policy.StrongNameMembershipCondition,
mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="UnionCodeGroup"
Description="System.Security.Policy.UnionCodeGroup, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="UrlMembershipCondition"
Description="System.Security.Policy.UrlMembershipCondition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="WebPartPermission"
Description="Microsoft.SharePoint.Security.WebPartPermission,
Microsoft.SharePoint.Security, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c"/>
<SecurityClass Name="ZoneMembershipCondition"
Description="System.Security.Policy.ZoneMembershipCondition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SqlClientPermission"
Description="System.Data.SqlClient.SqlClientPermission, System.Data,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</SecurityClasses>
<NamedPermissionSets>
<PermissionSet
class="NamedPermissionSet"
version="1"
Unrestricted="true"
Name="FullTrust"
Description="Allows full access to all
resources"
/>
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="Nothing"
Description="Denies all resources, including
the right to execute"
/>
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="ASP.Net">
<IPermission
class="AspNetHostingPermission"
version="1"
Level="Minimal"
/>
<IPermission
class="SecurityPermission"
version="1"
Flags="Execution"
/>
<IPermission class="WebPartPermission"
version="1"
Connections="True"
/>
</PermissionSet>
<PermissionSet class="NamedPermissionSet"
version="1" Name="WebPartLibrary1PermissionSet">
<IPermission class="AspNetHostingPermission" version="1" Level="Medium"
/>
<IPermission class="SecurityPermission" version="1" Flags="Assertion,
Execution, ControlThread, ControlPrincipal, RemotingConfiguration,
UnmanagedCode" />
<IPermission class="WebPartPermission" version="1" Connections="True" />
<IPermission class="SqlClientPermission" version="1"
AllowBlankPassword="False" />
</PermissionSet>
</NamedPermissionSets>
<CodeGroup
class="FirstMatchCodeGroup"
version="1"
PermissionSetName="Nothing">
<IMembershipCondition
class="AllMembershipCondition"
version="1"
/>
<CodeGroup
class="UnionCodeGroup" version="1"
PermissionSetName="WebPartLibrary1PermissionSet">
<IMembershipCondition
class="StrongNameMembershipCondition"
version="1"

PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000100B791C96EBFCD6E192C8998945A628B4E3F466EC49BFA4C812BCE256F6CB8BB734D2EAC64F6D0C3CFC52135C321B21C12476512369A0D5BCAD0ED80587C2655A34C6811D353219C680E955E47871281302233AFF8A0D4009F59299B3867DF61823E36FEAA55A5DB0ABDEE2EC39745068C5
8BF32E13F2709EC147890FD33B847D5" />
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="ASP.Net">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="$AppDirUrl$/*"
/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="$CodeGen$/*"
/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust">
<IMembershipCondition
class="UrlMembershipCondition"
Url="$Gac$/*"
version="1"
/>
</CodeGroup>
<CodeGroup class="UnionCodeGroup" version="1"
PermissionSetName="Nothing">
<IMembershipCondition
class="ZoneMembershipCondition"
version="1"
Zone="MyComputer" />
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Microsoft_Strong_Name"
Description="This code group grants code
signed with the Microsoft strong name full trust. ">
<IMembershipCondition

class="StrongNameMembershipCondition"
version="1"

PublicKeyBlob="002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D2
61C8A12436518206DC093344D5AD293"
/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Ecma_Strong_Name"
Description="This code group grants code
signed with the ECMA strong name full trust. ">
<IMembershipCondition

class="StrongNameMembershipCondition"
version="1"

PublicKeyBlob="00000000000000000400000000000000"
/>
</CodeGroup>
</CodeGroup>
</CodeGroup>
</PolicyLevel>
</policy>
</security>
</mscorlib>
</configuration>
 
A

António Pinho

Hi Mihai,

Thanks for your reply, but it didn't work. The error message is still there.
This is a default sharepoint installation, and a portal with just one site
(a blank site) on it. Any other suggestion?

Isn't there anyone that uses webparts with sql server, without raising the
trust level to full?



TIA




Mihai Durcau said:
Try to add in web.config the SQL Assembly in the SAFE section:

<SafeControls>
<SafeControl Assembly="System.Data.SqlClient, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="System.Web.UI.WebControls" TypeName="*" Safe="True" />
of course IISReset - don't forget where you are :)
MD

António Pinho said:
Hi,

I have a big problem with an webpart/assembly. i'm trying to connect to sql
server but i get the error "Request for the permission of type
System.Data.SqlClient.SqlClientPermission, System.Data, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.". i've searched for
it and can't find a clear answer. but one thing i'm sure: permissions.
if
i
change the trust level in the web.config of the sharepoint portal that i
created to full, everything works fine.

can someone help me?

TIA


code of the assembly, web.config, wss_minimaltrust_Custom.config

webpart/assembly

protected override void RenderWebPart(HtmlTextWriter output)
{
String strConn =
"server=myserver;database=mydb;uid=myuser;password=mypwd;";
SqlClientPermission permission = new
SqlClientPermission(PermissionState.Unrestricted);

try
{
permission.Demand();
permission.Assert();

SqlConnection Conn = new SqlConnection(strConn);
Conn.Open();
Conn.Close();
Conn.Dispose();
}
catch (Exception ex)
{
output.Write(ex.Message);
}
finally
{
output.Write(" the end");
};
}


web.config

<configuration>
<configSections>
<sectionGroup name="SharePoint">
<section name="SafeControls"
type="Microsoft.SharePoint.ApplicationRuntime.SafeControlsConfigurationHandl
er, Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" />
<section name="RuntimeFilter"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="WebPartLimits"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="WebPartCache"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="WebPartWorkItem"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="WebPartControls"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="SafeMode"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="OnlineLibrary"
type="System.Configuration.SingleTagSectionHandler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>
</configSections>
<SharePoint>
<SafeMode MaxControls="50" CallStack="false" />
<WebPartLimits MaxZoneParts="50" PropertySize="1048576" />
<WebPartCache Storage="CacheObject" />
<WebPartWorkItem Timeout="7000" />
<WebPartControls
DatasheetControlGuid="65BCBEE4-7728-41a0-97BE-14E1CAE36AAE" />
<!--
SafeControl Attributes:
Assembly="[Assembly]" - The .NET assembly in which the control is
contained. This attribute can also contain version, culture, and public key
token information.
Namespace="[Namespace]" - The .NET namespace in which the control
is defined.
TypeName="[Typename]" - The .NET class name of the control. You
can type an asterisk (*) wildcard character to indicate all TypeNames in a
Namespace.
Safe="[True|False]" - Specifies whether a Web Part or Web Form
Control is safe and can be displayed on a Web Parts Page. This attribute is
True by default.
-->
<SafeControls>
<SafeControl Assembly="System.Web, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="System.Web.UI.WebControls" TypeName="*" Safe="True" />
<SafeControl Assembly="System.Web, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="System.Web.UI.HtmlControls" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.WebPartPages" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.WebControls" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.ApplicationPages" TypeName="*" Safe="True"
/>
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.SoapServer" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.Meetings" TypeName="*" Safe="True" />
<SafeControl Assembly="Microsoft.SharePoint.Portal, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.Portal.WebControls" TypeName="*" />
<SafeControl Assembly="Microsoft.SharePoint.Portal, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Namespace="Microsoft.SharePoint.Portal.WebControls.Alerts" TypeName="*" />
<SafeControl Assembly="WebPartLibrary1, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=819bece51b5870e7"
Namespace="WebPartLibrary1" TypeName="*" Safe="True" />
</SafeControls>
<!--<OnlineLibrary Url="http://r.office.microsoft.com/r/hlidAwsGallery"
/>-->
<RuntimeFilter Assembly="Microsoft.SharePoint.Portal, Version=11.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c"
Class="Microsoft.SharePoint.Portal.Audience.AudienceManager"
BuilderURL="audience_chooser.aspx" />
</SharePoint>
<system.web>
<securityPolicy>
<trustLevel name="WSS_Medium" policyFile="C:\Program Files\Common
Files\Microsoft Shared\Web Server
Extensions\60\config\wss_mediumtrust.config" />
<trustLevel name="WSS_Minimal" policyFile="C:\Program Files\Common
Files\Microsoft Shared\Web Server
Extensions\60\config\wss_minimaltrust.config" />
<trustLevel name="WSS_Minimal_Custom" policyFile="C:\Program
Files\Common Files\Microsoft Shared\Web Server
Extensions\60\config\wss_minimaltrust_Custom.config" />
</securityPolicy>
<httpHandlers>
<add verb="*" path="/_vti_bin/*.aspx"
type="System.Web.UI.PageHandlerFactory, System.Web, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add verb="*" path="*.aspx"
type="Microsoft.SharePoint.ApplicationRuntime.SharePointHandlerFactory,
Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c" />
</httpHandlers>
<customErrors mode="On" />
<httpRuntime maxRequestLength="51200" />
<authentication mode="Windows" />
<authorization>
<allow users="*" />
</authorization>



wss_minimaltrust_Custom.config

<configuration>
<mscorlib>
<security>
<policy>
<PolicyLevel version="1">
<SecurityClasses>
<SecurityClass Name="AllMembershipCondition"
Description="System.Security.Policy.AllMembershipCondition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="AspNetHostingPermission"
Description="System.Web.AspNetHostingPermission, System, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="FirstMatchCodeGroup"
Description="System.Security.Policy.FirstMatchCodeGroup, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="NamedPermissionSet"
Description="System.Security.NamedPermissionSet"/>
<SecurityClass Name="SecurityPermission"
Description="System.Security.Permissions.SecurityPermission, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="StrongNameMembershipCondition"
Description="System.Security.Policy.StrongNameMembershipCondition,
mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="UnionCodeGroup"
Description="System.Security.Policy.UnionCodeGroup, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="UrlMembershipCondition"
Description="System.Security.Policy.UrlMembershipCondition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="WebPartPermission"
Description="Microsoft.SharePoint.Security.WebPartPermission,
Microsoft.SharePoint.Security, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c"/>
<SecurityClass Name="ZoneMembershipCondition"
Description="System.Security.Policy.ZoneMembershipCondition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SqlClientPermission"
Description="System.Data.SqlClient.SqlClientPermission, System.Data,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</SecurityClasses>
<NamedPermissionSets>
<PermissionSet
class="NamedPermissionSet"
version="1"
Unrestricted="true"
Name="FullTrust"
Description="Allows full access to all
resources"
/>
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="Nothing"
Description="Denies all resources, including
the right to execute"
/>
<PermissionSet
class="NamedPermissionSet"
version="1"
Name="ASP.Net">
<IPermission
class="AspNetHostingPermission"
version="1"
Level="Minimal"
/>
<IPermission
class="SecurityPermission"
version="1"
Flags="Execution"
/>
<IPermission class="WebPartPermission"
version="1"
Connections="True"
/>
</PermissionSet>
<PermissionSet class="NamedPermissionSet"
version="1" Name="WebPartLibrary1PermissionSet">
<IPermission class="AspNetHostingPermission" version="1" Level="Medium"
/>
<IPermission class="SecurityPermission" version="1" Flags="Assertion,
Execution, ControlThread, ControlPrincipal, RemotingConfiguration,
UnmanagedCode" />
<IPermission class="WebPartPermission" version="1"
Connections="True"
/>
<IPermission class="SqlClientPermission" version="1"
AllowBlankPassword="False" />
</PermissionSet>
</NamedPermissionSets>
<CodeGroup
class="FirstMatchCodeGroup"
version="1"
PermissionSetName="Nothing">
<IMembershipCondition
class="AllMembershipCondition"
version="1"
/>
<CodeGroup
class="UnionCodeGroup" version="1"
PermissionSetName="WebPartLibrary1PermissionSet">
<IMembershipCondition
class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="0024000004800000940000000602000000240000525341310004000001000100B791C96EBFCD6E192C8998945A628B4E3F466EC49BFA4C812BCE256F6CB8BB734D2EAC64F6D0C3CFC52135C321B21C12476512369A0D5BCAD0ED80587C2655A34C6811D353219C680E955E47871281302233AFF8A0D4009F59299B3867DF61823E36FEAA55A5DB0ABDEE2EC39745068C5
8BF32E13F2709EC147890FD33B847D5" />
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="ASP.Net">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="$AppDirUrl$/*"
/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust">
<IMembershipCondition
class="UrlMembershipCondition"
version="1"
Url="$CodeGen$/*"
/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust">
<IMembershipCondition
class="UrlMembershipCondition"
Url="$Gac$/*"
version="1"
/>
</CodeGroup>
<CodeGroup class="UnionCodeGroup" version="1"
PermissionSetName="Nothing">
<IMembershipCondition
class="ZoneMembershipCondition"
version="1"
Zone="MyComputer" />
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Microsoft_Strong_Name"
Description="This code group grants code
signed with the Microsoft strong name full trust. ">
<IMembershipCondition

class="StrongNameMembershipCondition"
version="1"
PublicKeyBlob="002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D2
61C8A12436518206DC093344D5AD293"
/>
</CodeGroup>
<CodeGroup
class="UnionCodeGroup"
version="1"
PermissionSetName="FullTrust"
Name="Ecma_Strong_Name"
Description="This code group grants code
signed with the ECMA strong name full trust. ">
<IMembershipCondition

class="StrongNameMembershipCondition"
version="1"

PublicKeyBlob="00000000000000000400000000000000"
/>
</CodeGroup>
</CodeGroup>
</CodeGroup>
</PolicyLevel>
</policy>
</security>
</mscorlib>
</configuration>
 
J

John

António Pinho said:
Hi Mihai,

Thanks for your reply, but it didn't work. The error message is still there.
This is a default sharepoint installation, and a portal with just one site
(a blank site) on it. Any other suggestion?

Isn't there anyone that uses webparts with sql server, without raising the
trust level to full?

You need to edit the wss_minimaltrust.config file.

Add:

<SecurityClass Name="SqlClientPermission"
Description="System.Data.SqlClient.SqlClientPermission, System.Data,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
/>

to the SecurityClasses section and

<IPermission class="SqlClientPermission" version="1"
Unrestricted="true" />

to the PermissionSet section with the attribute Name="ASP.Net"

If you're still having trouble, look through the
wss_mediumtrust.config for the SqlClientPermissions entries and try to
add them to wss_minimaltrust.config.

Be forewarned that it's possible that later patches to SPS2003 may
blow out your changes. There's a way to use a different file other
than wss_minimaltrust.config but I haven't looked for it yet.

uber1024
 
A

António Pinho

Working nice and smooth. Thanks do everyone.



John said:
"António Pinho" <[email protected]> wrote in message

You need to edit the wss_minimaltrust.config file.

Add:

<SecurityClass Name="SqlClientPermission"
Description="System.Data.SqlClient.SqlClientPermission, System.Data,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
/>

to the SecurityClasses section and

<IPermission class="SqlClientPermission" version="1"
Unrestricted="true" />

to the PermissionSet section with the attribute Name="ASP.Net"

If you're still having trouble, look through the
wss_mediumtrust.config for the SqlClientPermissions entries and try to
add them to wss_minimaltrust.config.

Be forewarned that it's possible that later patches to SPS2003 may
blow out your changes. There's a way to use a different file other
than wss_minimaltrust.config but I haven't looked for it yet.

uber1024
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top