本文介绍了找出SSIS中的项目名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以通过脚本任务或变量在 SSIS 中找出项目的名称?
Is it possible to figure out the name of the project while in SSIS either through a script task, or a variable?
我知道如何获取 PackageName 和 TaskName,但在本例中,我需要 ProjectName.
I know how to get the PackageName, and the TaskName, but in this case, I need the ProjectName.
推荐答案
诚然,这是 Holy-set-the-house-on-fire-hacktastic,但它在通过 SSDT 运行时有效......你需要几个此脚本任务的工作内容:
1. 要访问的变量,以便您可以爬到其父级.
2. 引用 Microsoft.SqlServer.DTSRuntimeWrap
This is, admittedly, holy-set-the-house-on-fire-hacktastic, but it works when run via SSDT... You need a couple of things for this Script Task to work:
1. A variable to access so you can climb to its parent.
2. A reference to Microsoft.SqlServer.DTSRuntimeWrap
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using RuntimeWrapper = Microsoft.SqlServer.Dts.Runtime.Wrapper;
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
RuntimeWrapper.IDTSProject100 p = ((RuntimeWrapper.IDTSProject100)((Package)Dts.Variables["User::myVar"].Parent).Project);
string projectName = GetProjectName(p);
Dts.TaskResult = (int)ScriptResults.Success;
}
private string GetProjectName(RuntimeWrapper.IDTSProject100 proj)
{
System.Reflection.PropertyInfo pInfo = proj.GetType().GetProperty("Project",
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance);
Project p = (Project)pInfo.GetValue(proj, null);
return p.Name;
}
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
}
这篇关于找出SSIS中的项目名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!