This may be naive but I cannot get any confirmation of this: When I write a SQL function via the SQLCLR and as a C# SQL Server Project, can the SQL function include any method/class/namespace in the .NET BCL? Are there any restrictions on what the function can do? I have full control of the SQL Server and its hosting OS, so I can amend security settings at that level. I am more interested in the language support for C# in a SQLCLR user-defined function (SQL project).
这可能是天真的,但我无法得到任何确认:当我通过SQLCLR和C#SQL Server项目编写SQL函数时,SQL函数是否可以包含.NET BCL中的任何方法/类/命名空间?功能可以做什么限制?我完全控制SQL Server及其托管操作系统,因此我可以修改该级别的安全设置。我对SQLCLR用户定义函数(SQL项目)中C#的语言支持更感兴趣。
My final deployment of code will be on SQL Server 2005 and 2008 R2 (Enterprise Edition). As 2008 R2 would be a development on 2005 in terms of features and support, 2005 is my common denominator, hence I am interested in answers on 2005.
我的最终代码部署将在SQL Server 2005和2008 R2(企业版)上。由于2008 R2在功能和支持方面将是2005年的发展,2005年是我的共同点,因此我对2005年的答案感兴趣。
Thanks
2 个解决方案
#1
1
It can not. You can't use classes that have a [HostProtection] attribute that marks the class as unsafe. Details are in this MSDN Library article, it includes lists of classes that are off limits.
这不可以。您不能使用具有[HostProtection]属性的类,该属性将该类标记为不安全。详细信息在此MSDN Library文章中,它包含不受限制的类列表。
The classic example of such a class is TimeZoneInfo, it loads an unmanaged DLL that won't be unloaded if there's a query abort.
这样一个类的经典示例是TimeZoneInfo,它会加载一个非托管DLL,如果查询中止,它将不会被卸载。
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort=true)]
public sealed class TimeZoneInfo : IEquatable<TimeZoneInfo>, ISerializable, IDeserializationCallback
{
// etc...
}
#2
2
The .NET version depends on the SQL Server version:
.NET版本取决于SQL Server版本:
- 2005 = .NET v2.0
- 2008/R2 = .NET v3.5
2005 = .NET v2.0
2008 / R2 = .NET v3.5
It's not full access to .NET - restrictions are based around the external_access parameter. See this link for more details: http://msdn.microsoft.com/en-us/library/ms345101.aspx
它不能完全访问.NET - 限制基于external_access参数。有关详细信息,请参阅此链接:http://msdn.microsoft.com/en-us/library/ms345101.aspx
#1
1
It can not. You can't use classes that have a [HostProtection] attribute that marks the class as unsafe. Details are in this MSDN Library article, it includes lists of classes that are off limits.
这不可以。您不能使用具有[HostProtection]属性的类,该属性将该类标记为不安全。详细信息在此MSDN Library文章中,它包含不受限制的类列表。
The classic example of such a class is TimeZoneInfo, it loads an unmanaged DLL that won't be unloaded if there's a query abort.
这样一个类的经典示例是TimeZoneInfo,它会加载一个非托管DLL,如果查询中止,它将不会被卸载。
[HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort=true)]
public sealed class TimeZoneInfo : IEquatable<TimeZoneInfo>, ISerializable, IDeserializationCallback
{
// etc...
}
#2
2
The .NET version depends on the SQL Server version:
.NET版本取决于SQL Server版本:
- 2005 = .NET v2.0
- 2008/R2 = .NET v3.5
2005 = .NET v2.0
2008 / R2 = .NET v3.5
It's not full access to .NET - restrictions are based around the external_access parameter. See this link for more details: http://msdn.microsoft.com/en-us/library/ms345101.aspx
它不能完全访问.NET - 限制基于external_access参数。有关详细信息,请参阅此链接:http://msdn.microsoft.com/en-us/library/ms345101.aspx