[英]SQLCLR Stored procedure datatypes
I decided to create a SQLCLR stored procedure to replace a SQL Server stored procedure due to it's complexity. 由于它的复杂性,我决定创建一个SQLCLR存储过程来替换SQL Server存储过程。
Question: is there any data type or API restrictions when we write CLR stored procedures? 问题:编写CLR存储过程时,是否有任何数据类型或API限制? If so, can someone give me any heads up on this.
如果是这样,有人可以给我任何建议。
I am planning to use var, List<T>, DataTable, DataRow[]
and a Queue
along with few LINQ
extension methods. 我打算使用
var, List<T>, DataTable, DataRow[]
和Queue
以及一些LINQ
扩展方法。
This is actually a fairly open-ended question as there are nuances in both what can be done in the .NET / CLR code itself and what datatypes can/should be used as input/output parameters. 实际上,这是一个相当开放的问题,因为.NET / CLR代码本身可以做什么以及可以/应该将哪些数据类型用作输入/输出参数都存在细微差别。
Starting with the basics, the nuances depend on what version of SQL Server you are using, and which particular question is being asked. 从基础开始,细微差别取决于您所使用的SQL Server版本以及所询问的特定问题。
Supported .NET Framework Libraries : 支持的.NET Framework库 :
Data Types: 资料类型:
Supported .NET Framework Libraries : ( 2 libraries added as noted below ) 支持的.NET Framework库 :( 添加了两个库,如下所述 )
Data Types: 资料类型:
Sql*
type available (eg SqlInt32
) then use it; Sql*
类型(例如SqlInt32
),则使用它;否则,使用它。 don't use the .NET type in the C# method for input parameters (eg int
or Int32
). int
或Int32
)。 Only use the native .NET type if there is no Sql*
type for the SQL Server Data Type to map to. Sql*
类型映射到SQL Server数据类型时,才使用本机.NET类型。 The two common instances of this exception are using object
(which can be DbNull.Value
) to map to SQL_VARIANT
, and DateTime
/ DateTime?
object
(可以是DbNull.Value
)映射到SQL_VARIANT
,以及DateTime
/ DateTime?
which map to DATETIME2
. DATETIME2
。 PERMISSION_SET
of UNSAFE
into the database in which your code also resides. PERMISSION_SET
的UNSAFE
进入你的代码还驻留的数据库。 You will also probably need to set the database to TRUSTWORTHY ON
in order to set them to UNSAFE
because it does not seem possible (not that I can find, anyway) to create the Asymmetric Key from Microsoft provided DLLs. TRUSTWORTHY ON
,以便将它们设置为UNSAFE
因为从Microsoft提供的DLL中似乎不可能(无论如何,我也找不到)。 List<T>
, DataTable
, and DataRow[]
. List<T>
, DataTable
和DataRow[]
时,我没有看到任何问题。 Queue
or var
but would not expect any issues when using them. Queue
或var
但是使用它们时不会出现任何问题。 LINQ
but seem to recall the only issue being that it was not included in the SQL Server 2005 set of supported Framework Libraries so that didn't work for me as I need to support 2005 - 2014, but for anyone who doesn't need to worry about SQL Server 2005 it should be ok. LINQ
已经有好几年了,但似乎回想起唯一的问题是它没有包含在SQL Server 2005支持的框架库集中,因此对我不起作用,因为我需要支持2005-2014,但是对于任何不需要担心SQL Server 2005的人都应该可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.