tags:

views:

192

answers:

2

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
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