开发者

Receiving SQL Server events from a CLR function

I wrote a CLR class with several methods, which are linked as functions in a SQL Server 2005 database. When several of these functions are used in scope of one transaction or connection, I need another one to be automatically executed to clean up some stuff, at the time of transaction or connection close (either time is good for now, later I will decide which is best). I figure that receiving events from another new CLR functions can do, but I don't know how to achieve that.

Can anyone point me to information on modules, documents or whatever, that can help me understand how to receive transaction or connection closing events in a CLR class, or how to execute a particular function when these events occur?

EDIT: I created a C# class with a static member to store values, and two static methods to set and get values from the member. Compiled as a DLL and added it as an assembly to SQL Server 2005. Methods were added as CLR functions to the same server. Combining different connections and transactions to get and set values alternatively, took me to see that the static member is not being reseted. I am hoping for an automatic way to enclose the stored values into one transaction开发者_运维知识库 or connection (or to clean up the static member), so values stored by each do not interfere with the other


SQLCLR, as in CLR running inside SQL Server, runs code only when you CLR code is invoked from a function, procedure, aggregate or CLR type method. CLR code cannot keep state between invocations, therefore there cannot be any possible reason to run cleanup code. There are no callbacks for transaction commit, connection close module unload or anything similar. They are not needed, nor supported.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜