简体   繁体   English

编写CLR存储过程

[英]Write a CLR stored procedure

I would like to use existing Delphi code to write SQL Server stored procedures. 我想使用现有的Delphi代码编写SQL Server存储过程。

In the past I used extended stored procedures, somehow a dll compiled by Delphi wrapped by a SQL Server extended stored procedure. 在过去,我使用扩展存储过程,即由Delphi编译的dll被SQL Server扩展存储过程包装。

Extended stored procedures are now deprecated, so somehow I wonder if there is a solution, even in the "trick domain", like some sample CLR code that wraps a normal dll or something like that. 现在不建议使用扩展存储过程,所以我不知道是否存在一种解决方案,即使在“技巧域”中也是如此,例如一些包装普通dll的示例CLR代码或类似的东西。

Just to give you an example: 仅举一个例子:

I insert in the db some documents by encrypting them and I would like to create a kind of API based on SQL Server functions / procedures for inserting or reading documents, so other people accessing sql server can call those functions. 我通过加密将一些文档插入db中,我想创建一种基于SQL Server函数的API,用于插入或读取文档,因此其他访问sql server的人可以调用这些函数。

Of course an alternative solution is to use webservices but I would like to try the SQL Server way first. 当然,另一种解决方案是使用Web服务,但是我想先尝试使用SQL Server。

Note: I don't want to use Delphi Prism, my code is for XE2. 注意:我不想使用Delphi Prism,我的代码用于XE2。

Unsafe SQLCLR assemblies can p-invoke native dlls. 不安全的SQLCLR程序集可以p调用本机dll。 A better way would be to expose the native DLL services as a COM interface and use COM interop from SQLCLR, or even call the COM APIs directly from SQL via OLE Automation Procedures . 更好的方法是将本机DLL服务公开为COM接口,并使用来自SQLCLR的COM互操作 ,甚至可以通过OLE Automation Procedures直接从SQL调用COM API。 An even better way would be to rewrite the Delphi code as CLR code and invoke it directly as SQLCLR procedure. 更好的方法是将Delphi代码重写为CLR代码,并直接作为SQLCLR过程调用它。 And the best way would be to use SQL Server native encryption features . 最好的方法是使用SQL Server 本机加密功能

Not to mention the fact that CLR in SQL Server is a guaranteed deep performance hit. 更不用说SQL Server中的CLR保证了良好的性能下降。 Keep to the standard CRUD operators and you should be fine. 遵循标准的CRUD运算符,您应该会满意。 The other way to do it is to use the file system as your encryption mechanism. 另一种方法是使用文件系统作为加密机制。 If you are only trying to prevent casual access to docs this is a fine way to go. 如果您只是想防止随意访问文档,这是一个不错的方法。 Otherwise it might be time to rethink your access protocol. 否则,可能是时候重新考虑您的访问协议了。

CLR in SQL Server is a convenient bad idea. SQL Server中的CLR是一个方便的坏主意。 Use it sparingly if at all. 尽量不要使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM