C # Class Library Integration in SQL Server

I am trying to test the functionality of the CLR functions in SQL Server 2012. I found a tutorial on the Internet on how to basically do this and make it work on my server. ( https://www.skylinetechnologies.com/Blog/Skyline-Blog/March-2013/CLR-Functions-in-SQL-Server-A-Tutorial )

Now I wanted to create a function that does not return a table, but instead. In my opinion, SQL Server needs some kind of object to work, so I tried it using the following testing method:

 public static class  TestSingleValue
{
  [SqlFunction(DataAccess = DataAccessKind.None, FillRowMethodName = "MyFillRowMethod", IsDeterministic = true)]

  public static SqlChars Test123()
    {
        SqlChars test = new SqlChars("teststring");
        return test;

    }

}

On the SQL server, I did the following:

ALTER ASSEMBLY ClassLibrary2 from 'D:\SQL\TestCLR\ClassLibrary2.dll' with Permission_set = SAFE
CREATE FUNCTION TestCLR()
  returns nvarchar(max)
    AS 
       EXTERNAL name ClassLibrary2.[CLRTest.TestSingleValue].Test123
 GO 

Execute TestCLR

SQL Server throws an error when executing the test method, saying that "The reference to the object is not installed on the instance of the object" and further:

System.NullReferenceException: System.Data.SqlServer.Internal.ClrLevelContext.GetCurrentContextForLobAccess( → CClrLobContext * pLobContext)  System.Data.SqlServer.Internal.ClrLevelContext.GetXvarWlobStream(CXVariantBasepxvarSource, XvarLOBStreamInitCode eCode, Int64 lcid, SqlCompareOptions compareOpts, CClrLobContext pLobContext).

- , , , , ? . .

+4
1

, , "nvarchar (max)" . nvarchar , . : CLR Nvarchar (max)?

+1

Source: https://habr.com/ru/post/1691882/


All Articles