By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,640 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,640 IT Pros & Developers. It's quick & easy.

webparts & sqlclientpermission

P: n/a
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.Safe ControlsConfigurationHandl
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.Audien ceManager"
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.confi g" />
</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.Shar ePointHandlerFactory,
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.AllMembershipC ondition, 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.FirstMatchCode Group, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="NamedPermissionSet"
Description="System.Security.NamedPermissionSet"/>
<SecurityClass Name="SecurityPermission"
Description="System.Security.Permissions.SecurityP ermission, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="StrongNameMembershipCondition"
Description="System.Security.Policy.StrongNameMemb ershipCondition, 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.UrlMembershipC ondition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="WebPartPermission"
Description="Microsoft.SharePoint.Security.WebPart Permission,
Microsoft.SharePoint.Security, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c"/>
<SecurityClass Name="ZoneMembershipCondition"
Description="System.Security.Policy.ZoneMembership Condition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SqlClientPermission"
Description="System.Data.SqlClient.SqlClientPermis sion, 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="00240000048000009400000006020000002 40000525341310004000001000
100B791C96EBFCD6E192C8998945A628B4E3F466EC49BFA4C8 12BCE256F6CB8BB734D2EAC64F
6D0C3CFC52135C321B21C12476512369A0D5BCAD0ED80587C2 655A34C6811D353219C680E955
E47871281302233AFF8A0D4009F59299B3867DF61823E36FEA A55A5DB0ABDEE2EC39745068C5
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="00240000048000009400000006020000002 40000525341310004000001000
10007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87F B03766C834C99921EB23BE79AD
9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC60 7774F29E8320E92EA05ECE4E82
1C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D7 45D6F2DE5F17E5EAF0FC4963D2
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>

Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <aj******@hotmail.com> wrote in message
news:OL**************@tk2msftngp13.phx.gbl...
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.Safe ControlsConfigurationHandl 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.Audien ceManager"
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.confi g" />
</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.Shar ePointHandlerFactory,
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.AllMembershipC ondition, 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.FirstMatchCode Group, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="NamedPermissionSet"
Description="System.Security.NamedPermissionSet"/>
<SecurityClass Name="SecurityPermission"
Description="System.Security.Permissions.SecurityP ermission, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="StrongNameMembershipCondition" Description="System.Security.Policy.StrongNameMemb ershipCondition, 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.UrlMembershipC ondition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="WebPartPermission"
Description="Microsoft.SharePoint.Security.WebPart Permission,
Microsoft.SharePoint.Security, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c"/>
<SecurityClass Name="ZoneMembershipCondition"
Description="System.Security.Policy.ZoneMembership Condition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SqlClientPermission"
Description="System.Data.SqlClient.SqlClientPermis sion, 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="00240000048000009400000006020000002 40000525341310004000001000 100B791C96EBFCD6E192C8998945A628B4E3F466EC49BFA4C8 12BCE256F6CB8BB734D2EAC64F 6D0C3CFC52135C321B21C12476512369A0D5BCAD0ED80587C2 655A34C6811D353219C680E955 E47871281302233AFF8A0D4009F59299B3867DF61823E36FEA A55A5DB0ABDEE2EC39745068C5 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="00240000048000009400000006020000002 40000525341310004000001000 10007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87F B03766C834C99921EB23BE79AD 9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC60 7774F29E8320E92EA05ECE4E82 1C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D7 45D6F2DE5F17E5EAF0FC4963D2 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>


Nov 18 '05 #2

P: n/a
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" <md*****@mdsi.ca> wrote in message
news:e%****************@TK2MSFTNGP09.phx.gbl...
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" <aj******@hotmail.com> wrote in message
news:OL**************@tk2msftngp13.phx.gbl...
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.Safe ControlsConfigurationHandl 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.Audien ceManager"
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.confi g" />
</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.Shar ePointHandlerFactory,
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.AllMembershipC ondition, 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.FirstMatchCode Group, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="NamedPermissionSet"
Description="System.Security.NamedPermissionSet"/>
<SecurityClass Name="SecurityPermission"
Description="System.Security.Permissions.SecurityP ermission, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass

Name="StrongNameMembershipCondition"
Description="System.Security.Policy.StrongNameMemb ershipCondition,

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.UrlMembershipC ondition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="WebPartPermission"
Description="Microsoft.SharePoint.Security.WebPart Permission,
Microsoft.SharePoint.Security, Version=11.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c"/>
<SecurityClass Name="ZoneMembershipCondition"
Description="System.Security.Policy.ZoneMembership Condition, mscorlib,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<SecurityClass Name="SqlClientPermission"
Description="System.Data.SqlClient.SqlClientPermis sion, 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="00240000048000009400000006020000002 40000525341310004000001000

100B791C96EBFCD6E192C8998945A628B4E3F466EC49BFA4C8 12BCE256F6CB8BB734D2EAC64F

6D0C3CFC52135C321B21C12476512369A0D5BCAD0ED80587C2 655A34C6811D353219C680E955

E47871281302233AFF8A0D4009F59299B3867DF61823E36FEA A55A5DB0ABDEE2EC39745068C5
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="00240000048000009400000006020000002 40000525341310004000001000

10007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87F B03766C834C99921EB23BE79AD

9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC60 7774F29E8320E92EA05ECE4E82

1C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D7 45D6F2DE5F17E5EAF0FC4963D2
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>



Nov 18 '05 #3

P: n/a
"António Pinho" <aj******@hotmail.com> wrote in message news:<Oo**************@tk2msftngp13.phx.gbl>...
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.SqlClientPermis sion, 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
Nov 18 '05 #4

P: n/a


Working nice and smooth. Thanks do everyone.

"John" <dj*****@hotmail.com> wrote in message
news:d0**************************@posting.google.c om...
"António Pinho" <aj******@hotmail.com> wrote in message

news:<Oo**************@tk2msftngp13.phx.gbl>...
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.SqlClientPermis sion, 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

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.