I am getting 'drop assembly failed because it is referenced by object' error. As I understand I need to drop all functions referenced to this assembly before it's drop. Is there any universal way how to do that?
To determine if CLR is enabled, execute the following commands: EXEC SP_CONFIGURE 'show advanced options', '1'; RECONFIGURE WITH OVERRIDE; EXEC SP_CONFIGURE 'clr enabled';
Deployed User CLR assemblies are stored in the database you deploy them to, not on the file system. the column called content contains binary data is the assembly.
NET Framework common language runtime (CLR), instead of in Transact-SQL. An assembly in SQL Server is an object that references a managed application module (. dll file) that was created in the . NET Framework common language runtime. An assembly contains class metadata and managed code.
CLR functions can be used to access external resources such as files, network resources, Web Services, other databases (including remote instances of SQL Server). This can be achieved by using various classes in the . NET Framework, such as System.IO , System.
You'll need a little script like that:
DECLARE @sql NVARCHAR(MAX) = N'';
DECLARE @assembly_name NVARCHAR(MAX)='assembly'
SELECT @sql += '
DROP ' +
CASE
WHEN o.type='PC' THEN 'PROCEDURE '
ELSE 'FUNCTION '
END
+ QUOTENAME(o.Name)
+ ';'
FROM Sys.Assemblies asm
INNER JOIN SYS.ASSEMBLY_MODULES m ON asm.assembly_id=m.assembly_id
INNER JOIN SYS.OBJECTS o ON m.object_id = o.object_id
WHERE asm.name=@assembly_name
SET @sql=@sql+'
DROP ASSEMBLY '+QUOTENAME(@assembly_name)
PRINT @sql;
EXEC sp_executesql @sql;
However, dropping all assembly's dependent objects is not safe, so take care what will be deleted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With