SQL CLR: Streaming table valued function results

前端 未结 3 2168
滥情空心
滥情空心 2021-02-10 15:24

My issue is very similar to this issue.

However, I\'m using SQL Server 2005 Service Pack 2 (SP2) (v9.0.3042) and the solution posted there does not work for me. I tried

3条回答
  •  悲&欢浪女
    2021-02-10 16:20

    The original problem is due to use of the yield keyword within your function, as explained in this question: SqlFunction fails to open context connection despite DataAccessKind.Read present.

    If you avoid using yield (store results in an intermediate array, return the whole lot at the end) the problem goes away.

    Alternatively you can do as you describe and avoid using the context connection, but if you do that you have to mark your assembly for external access as you describe. I think that's best described as a workaround, rather than a solution, given you lose some of the benefits available from a context connection and because of all the extra hoops you have to jump through.

    In many cases the benefit of being able to use streaming behaviour (yield) does outweigh this pain, but it's still worth considering both options.

    Here's the bug on Connect: http://connect.microsoft.com/SQLServer/feedback/details/442200/sql-server-2008-clr-tvf-data-access-limitations-break-existing-code

提交回复
热议问题