I've created an application to synchronize Microsoft SQL Server databases with the same structure. One of the tasks I need to solve is to transfer any database routine (procedure, function, trigger, etc) from source database to target one. For routine transfer I use a query
SELECT [definition] FROM sys.sql_modules WITH (NOLOCK) WHERE object_id = OBJECT_ID('SOME_OBJECT_ID') or
SELECT * FROM INFORMATION_SCHEMA.ROUTINES where routine_name like '%SOME_ROUTINE_NAME%' And it works perfectly for all the routines except CLR functions (the functions with [type_desc] = CLR_TABLE_VALUED_FUNCTION or [type_desc] = CLR_SCALAR_FUNCTION).
Their text is not stored in sys.sql_modules datatable and system view INFORMATION_SCHEMA.ROUTINES contains values [ROUTINE_BODY] = EXTERNAL and [ROUTINE_DEFINITION] = NULL.
But I'm sure that CLR function text is not recreated every time I open it because it can be changed and saved with user changes.
So I'd be very grateful for any hint about CLR function text location.
UPDATE: I don't needed to transfer .NET library function itself, I just want to transfer the wrapper function that is created manually in Programmability > Functions > Table-valued Functions.
CREATE FUNCTION [dbo].[len_s] (@str nvarchar(4000)) RETURNS bigint AS EXTERNAL NAME [SurrogateStringFunction].[Microsoft.Samples.SqlServer.SurrogateStringFunction].[LenS];?