我正在研究SSIS包(这对我来说是新的)。我使用脚本组件作为源,我使用ReadOnlyVariable(VarPackagePath)并为其分配一个值' C:\ Development \ SSISProjects \ VS2012 \ GetErrorColumn \ GetErrorColumn \ Package.dtsx'这是项目的位置。 我使用的脚本是获取发生错误的relavent列。 我关注的链接:http://www.techbrothersit.com/2013/12/ssis-how-to-get-error-column-name-in.html
我调试了我的c#代码,我在这一行收到错误:
TaskName = ExecutableNode.SelectSingleNode("DTS:Property[@DTS:Name='ObjectName']", NameSpcMgr).InnerText;
错误是:'Object reference not set to an instance of an object'
。
我的C#代码:
public override void CreateNewOutputRows()
{
/*
Add rows by calling the AddRow method on the member variable named "<Output Name>Buffer".
For example, call MyOutputBuffer.AddRow() if your output was named "MyOutput".
*/
//Declare Variables
String TaskName;
String ColName;
Int32 ColLineageID;
String ColKey;
//Read the Package File
XmlDocument PackageFile = new XmlDocument();
PackageFile.Load(Variables.VarPackagePath);
//Create Hash Table
Hashtable ColKeyTable = new Hashtable();
XmlNamespaceManager NameSpcMgr = new XmlNamespaceManager(PackageFile.NameTable);
NameSpcMgr.AddNamespace("DTS", "www.microsoft.com/SqlServer/Dts");
foreach (XmlNode childnode in PackageFile.SelectNodes("//*[@lineageId != '' and @name != '']"))
{
XmlNode ExecutableNode = childnode.SelectSingleNode("ancestor::DTS:Executable[1]", NameSpcMgr);
TaskName = ExecutableNode.SelectSingleNode("DTS:Property[@DTS:Name='ObjectName']", NameSpcMgr).InnerText;
ColName = childnode.Attributes["name"].Value;
ColLineageID = Convert.ToInt32(childnode.Attributes["lineageId"].Value);
ColKey = TaskName + ColName + ColLineageID;
if (!ColKeyTable.ContainsKey(ColKey))
{
ColKeyTable.Add(ColKey, DBNull.Value);
Output0Buffer.AddRow();
Output0Buffer.ColLineageID = ColLineageID;
Output0Buffer.ColName = ColName;
Output0Buffer.TaskName = TaskName;
}
}
}
请提供任何帮助/建议。