I need to use SMO to find out all the dependencies of a registered assembly (SQLCLR). How can I do that? Thanks, Nestor
A:
I guess I can query it using TSQL:
select
a.name as 'assembly',
(select name from sys.assemblies where assembly_id = r.referenced_assembly_id) as 'referenced_assembly'
from sys.assemblies a left outer join sys.assembly_references r on (a.assembly_id=r.assembly_id)
where a.is_user_defined = 1
order by assembly
:-)
Nestor
2009-09-30 22:48:52
A:
Actually, here is a better answer:
static public List<Urn> GetDependencies(SqlAssembly assembly)
{
return GetDependencies(assembly.Parent.Parent, assembly.Urn);
}
static public List<Urn> GetDependencies(Server server, Urn obj)
{
Scripter scr = new Scripter(server);
DependencyTree tree = scr.DiscoverDependencies(new Urn[] { obj }, DependencyType.Parents);
DependencyWalker depwalker = new DependencyWalker();
DependencyCollection depcoll = depwalker.WalkDependencies(tree);
List<Urn> dependencies = new List<Urn>();
foreach (DependencyCollectionNode dep in depcoll) dependencies.Add(dep.Urn);
return dependencies;
}
Nestor
2009-10-03 20:08:51