0
我正在以编程方式创建包含作为源的脚本组件的数据流任务的程序包。我已经能够创建包,数据流任务,并添加一个脚本组件。但是,脚本组件似乎默认为转换。以编程方式创建脚本组件作为源程序
有谁知道如何让它成为一个Souce?
这里是我的类的一个方法我工作:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DynamicPackageCreator.Models;
using Microsoft.SqlServer.Dts.Runtime;
using System.IO;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
// Alias to prevent ambiguity
using dtsColumnDataType = Microsoft.SqlServer.Dts.Runtime.Wrapper.DataType;
namespace DynamicPackageCreator
{
public class DtsClient
{
public void CreatePackageWithDataFlowAndScriptSource(string filePath, string dataFlowName, string sourceName, List<OutputDefinition> outputDefinitions)
{
// Create the Package
Package pkg = new Package();
pkg.Name = Path.GetFileNameWithoutExtension(filePath);
// Create the Dataflow task
Executable e = pkg.Executables.Add("STOCK:PipelineTask");
TaskHost thMainPipe = e as TaskHost;
thMainPipe.Name = dataFlowName;
MainPipe dataFlowTask = thMainPipe.InnerObject as MainPipe;
// Create Source Component
IDTSComponentMetaData100 sourceComponent = dataFlowTask.ComponentMetaDataCollection.New();
sourceComponent.Name = sourceName;
sourceComponent.ComponentClassID = SsisComponentType.ScriptComponent.GetComponentClassId();
// Get the design time srcDesignTime of the component
CManagedComponentWrapper srcDesignTime = sourceComponent.Instantiate();
// Initialize the component
srcDesignTime.ProvideComponentProperties();
int lastOutputId = 0;
// Add metadata
foreach (var outputDefinition in outputDefinitions)
{
var output = srcDesignTime.InsertOutput(DTSInsertPlacement.IP_AFTER, lastOutputId);
output.Name = outputDefinition.OutputName;
lastOutputId = output.ID;
var outputColumnCollection = output.OutputColumnCollection;
foreach (var outputColumnDefinition in outputDefinition.OutputColumnDefinitions)
{
var outputColumn = outputColumnCollection.New();
outputColumn.Name = outputColumnDefinition.ColumnName;
outputColumn.SetDataTypeProperties(dtsColumnDataType.DT_WSTR, outputColumnDefinition.ColumnSize, 0, 0, 0);
}
}
// Reinitialise the metadata
srcDesignTime.ReinitializeMetaData();
// Save the package
Application app = new Application();
app.SaveToXml(filePath, pkg, null);
}
}
}
的OutputDefinition类是我举办创建输出时使用的定义创建一个自定义类。