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.
If you want to look into CLR function or procedure you need to perform some steps as CLR functions an procedures are created from assemblies.
Step-1:- Export your assemblies to file system
Step-2:- Use .net assembly Decompiler like http://ilspy.net/ or redgate reflector
This method will work if assembly creator has not performed addition steps to prevent de-compilation.
Server Profiler has shown 35 different dynamic queries used by Management Studio to build the CLR wrapper function. So function text is unfortunately built on-the-fly and nothing is stored in the depths of system databases.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.