SqlFunction fails to open context connection despite DataAccessKind.Read present

烂漫一生 提交于 2019-12-01 03:23:14
Nestor

The problem is the following:

  1. SQLCLR does not allow any data access inside TestFillRow

  2. Even though it "looks" like your TestFillRow doesnt access data, the way the compiler translates code with "yield" statements is by actually deferring it's execution until the first .MoveNext() call to the iterator. Therefore the following statement:

    using (SqlConnection con = new SqlConnection("context connection=true"))        
    

    gets executed inside TestFillRow... which is illegal.

Do not use yield return; instead load the whole result to a List<> and return the list at the end of the UD Function.

mshakurov

"SQLCLR does not allow any data access inside TestFillRow" is a mistake.

If you don't use context connection = true connetion string you can access data inside FillRow method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!