SMO - 程序集依赖项

时间:2009-09-30 21:00:45

标签: smo

我需要使用SMO来找出已注册程序集(SQLCLR)的所有依赖项。 我怎样才能做到这一点? 谢谢,内斯特

2 个答案:

答案 0 :(得分:2)

实际上,这是一个更好的答案:

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

答案 1 :(得分:0)

我想我可以使用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

: - )