Udostępnij za pośrednictwem


Host Protection Attributes and CLR Integration Programming

New: 14 April 2006

The common language runtime (CLR) provides a mechanism to annotate managed application programming interfaces (APIs) that are part of the .NET Framework with certain attributes that may be of interest to a host of the CLR, such as Microsoft SQL Server 2005. Examples of such host protection attributes (HPAs) include:

  • SharedState, which indicates whether the API exposes the ability to create or manage shared state (for example, static class fields).
  • Synchronization, which indicates whether the API exposes the ability to perform synchronization between threads.
  • ExternalProcessMgmt, which indicates whether the API exposes a way to control the host process.

Given these attributes, SQL Server 2005 specifies a list of HPAs that are disallowed in the hosted environment through code access security (CAS). The CAS requirements are specified by one of three SQL Server permission sets: SAFE, EXTERNAL_ACCESS, or UNSAFE. One of these three security levels is specified when the assembly is registered on the server, using the CREATE ASSEMBLY statement. Code executing within the SAFE or EXTERNAL_ACCESS permission sets must avoid certain types or members that have the System.Security.Permissions.HostProtectionAttribute attribute applied. For more information, see CLR Integration Code Access Security and CLR Integration Programming Model Restrictions.

The HostProtectionAttribute is not a security permission as much as a way to improve reliability, in that it identifies specific code constructs, either types or methods, that the host may disallow. The use of the HostProtectionAttribute enforces a programming model that helps protect the stability of the host.

Host Protection Attributes

HPAs identify types or members that do not fit the host programming model and represent the following increasing levels of reliability threat:

  • Are otherwise benign.
  • Could lead to destabilization of server-managed user code.
  • Could lead to destabilization of the server process itself.

SQL Server disallows the use of a type or member that has a HostProtectionAttribute that specifies a System.Security.Permissions.HostProtectionResource enumeration with a value of ExternalProcessMgmt, ExternalThreading, MayLeakOnAbort, SecurityInfrastructure, SelfAffectingProcessMgmnt, SelfAffectingThreading, SharedState, Synchronization, or UI. This prevents the assemblies from calling members that enable sharing state, perform synchronization, might cause a resource leak on termination, or affect the integrity of the SQL Server process.

Disallowed Types and Members

The following topics identify types and members whose HostProtectionResource values are disallowed by SQL Server.

Note

The lists in these topics were generated from the supported assemblies of version 2.0.50727 of the .NET Framework. For more information, see Supported .NET Framework Libraries.

Topic Description

Disallowed Types and Members In Microsoft.VisualBasic.dll

Lists the types and members in Microsoft.VisualBasic.dll whose HPA values are disallowed.

Disallowed Types and Members In mscorlib.dll

Lists the types and members in mscorlib.dll whose HPA values are disallowed.

Disallowed Types and Members In System.dll

Lists the types and members in System.dll whose HPA values are disallowed.

Disallowed Types and Members In System.Data.dll

Lists the types and members in System.Data.dll whose HPA values are disallowed.

See Also

Concepts

CLR Integration Code Access Security
CLR Integration Programming Model Restrictions
Creating an Assembly

Help and Information

Getting SQL Server 2005 Assistance