我有一个收集扩展错误信息的SSIS脚本任务。
脚本的内容如下:
/// <summary>
/// ScriptMain is the entry point class of the script. Do not change the name, attributes,
/// or parent of this class.
/// </summary>
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
Dictionary<string, string> lineageIds = null;
public void Main()
{
// Grab the executables so we have to something to iterate over, and initialize our lineageIDs list
// Why the executables? Well, SSIS won't let us store a reference to the Package itself...
Dts.Variables["User::execsObj"].Value = ((Package)Dts.Variables["User::execsObj"].Parent).Executables;
Dts.Variables["User::lineageIds"].Value = new Dictionary<string, string>();
lineageIds = (Dictionary<string, string>)Dts.Variables["User::lineageIds"].Value;
Executables execs = (Executables)Dts.Variables["User::execsObj"].Value;
ReadExecutables(execs);
Dts.TaskResult = (int)ScriptResults.Success;
}
private void ReadExecutables(Executables executables)
{
foreach (Executable pkgExecutable in executables)
{
if (object.ReferenceEquals(pkgExecutable.GetType(), typeof(Microsoft.SqlServer.Dts.Runtime.TaskHost)))
{
TaskHost pkgExecTaskHost = (TaskHost)pkgExecutable;
if (pkgExecTaskHost.CreationName.StartsWith("SSIS.Pipeline"))
{
ProcessDataFlowTask(pkgExecTaskHost);
}
}
else if (object.ReferenceEquals(pkgExecutable.GetType(), typeof(Microsoft.SqlServer.Dts.Runtime.ForEachLoop)))
{
// Recurse into FELCs
ReadExecutables(((ForEachLoop)pkgExecutable).Executables);
}
}
}
private void ProcessDataFlowTask(TaskHost currentDataFlowTask)
{
MainPipe currentDataFlow = (MainPipe)currentDataFlowTask.InnerObject;
foreach (IDTSComponentMetaData100 currentComponent in currentDataFlow.ComponentMetaDataCollection)
{
// Get the inputs in the component.
foreach (IDTSInput100 currentInput in currentComponent.InputCollection)
foreach (IDTSInputColumn100 currentInputColumn in currentInput.InputColumnCollection)
lineageIds.Add(currentDataFlowTask.ID.ToString() + currentInputColumn.ID, currentInputColumn.Name);
// Get the outputs in the component.
foreach (IDTSOutput100 currentOutput in currentComponent.OutputCollection)
foreach (IDTSOutputColumn100 currentoutputColumn in currentOutput.OutputColumnCollection)
lineageIds.Add(currentDataFlowTask.ID.ToString() + currentoutputColumn.ID, currentoutputColumn.Name);
}
}
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
}
这曾经在SQL Server 2014上正常工作。但是,由于升级到SQL server 2017,该任务在线上显示以下错误消息:
MainPipe currentDataFlow = (MainPipe)currentDataFlowTask.InnerObject;
ST_47767930511349f4b94ba74c27240570中发生了类型为“System.InvalidCastException”的异常,但未在用户代码中进行处理
其他信息:无法将类型为“System.__ComObject”的COM对象强制转换为接口类型'Microsoft.SqlServer.Dts.Pipeline.Wrapper.MainPipe'.此操作失败,原因是由于以下错误,对COM组件的QueryInterface调用失败:不支持此类接口(来自HRESULT的异常: 0x80004002 (E_NOINTERFACE))。
在升级到SQL Server 2017之后,还有没有人看到过这种情况?
发布于 2019-03-22 00:28:01
原来,currentDataFlowTask.InnerObject返回的Com对象来自较新版本的Microsoft.SqlServer.DTSPipelineWrap。
为了解决这个问题,我删除了对Microsoft.SqlServer.DTSPipelineWrap的引用,并将其替换为同一程序集的版本14。
然后我修改了下面这一行:
MainPipe currentDataFlow = (MainPipe)currentDataFlowTask.InnerObject;
至
IDTSPipeline130 currentDataFlow = (IDTSPipeline130)currentDataFlowTask.InnerObject;
https://stackoverflow.com/questions/55282203
复制相似问题