这似乎对我有用。我创建了一个RaiseChangedEvent
设置为 true 的变量。然后我有一个 For Loop 递增该值。我在 for 循环中有一个脚本任务,用于记录 OnVariableValueChanged 事件的值和附加到包的事件处理程序。我有一个序列容器和一个脚本任务(已禁用)。如果我在容器上放置一个断点,我可以看到它正在被调用。尽管与控制流中的代码相同,但在此处启用脚本任务会导致锁定变量的超时错误。/耸耸肩
<!-- http://stackoverflow.com/q/42945383/181965 -->
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<Packages>
<Package Name="so_42945383" >
<Variables>
<Variable DataType="Int32" Name="IndexCurrent" RaiseChangedEvent="true">-1</Variable>
<Variable DataType="Int32" Name="IndexStart">0</Variable>
<Variable DataType="Int32" Name="IndexStop">1</Variable>
</Variables>
<Tasks>
<ForLoop Name="FLT Modify values" ConstraintMode="Linear">
<InitializerExpression><![CDATA[@[User::IndexCurrent] = @[User::IndexStart]]]></InitializerExpression>
<LoopTestExpression><![CDATA[@[User::IndexCurrent] <= @[User::IndexStop]]]></LoopTestExpression>
<CountingExpression><![CDATA[@[User::IndexCurrent] = @[User::IndexCurrent] + 1]]></CountingExpression>
<Tasks>
<Container Name="SEQC Do nothing" />
<Script ProjectCoreName="FLT_ST_EchoBack" Name="SCR Echo Back FLT">
<ScriptTaskProjectReference ScriptTaskProjectName="ST_EchoBack" />
</Script>
</Tasks>
</ForLoop>
</Tasks>
<Events>
<Event Name="OVVC" EventType="OnVariableValueChanged">
<Tasks>
<Container Name="SEQC Do nothing" />
<Script ProjectCoreName="OVCC_ST_EchoBack" Name="SCR Echo Back OVVC" Disabled="true">
<ScriptTaskProjectReference ScriptTaskProjectName="ST_EchoBack" />
</Script>
</Tasks>
</Event>
</Events>
</Package>
</Packages>
<ScriptProjects>
<ScriptTaskProject ProjectCoreName="ST_EchoBack" Name="ST_EchoBack" VstaMajorVersion="0">
<ReadOnlyVariables>
<!-- List all the variables you are interested in tracking -->
<Variable Namespace="User" VariableName="IndexCurrent" DataType="Int32" />
<Variable Namespace="User" VariableName="IndexStart" DataType="Int32" />
<Variable Namespace="User" VariableName="IndexStop" DataType="Int32" />
</ReadOnlyVariables>
<Files>
<File Path="ScriptMain.cs" BuildAction="Compile">using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
namespace ST_EchoBack
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
bool fireAgain = false;
string message = "{0}::{1} : {2}";
foreach (var item in Dts.Variables)
{
Dts.Events.FireInformation(0, "SCR Echo Back", string.Format(message, item.Namespace, item.Name, item.Value), string.Empty, 0, ref fireAgain);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
}
} </File>
<File Path="Properties\AssemblyInfo.cs" BuildAction="Compile">
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyVersion("1.0.*")]
</File>
</Files>
<AssemblyReferences>
<AssemblyReference AssemblyPath="System" />
<AssemblyReference AssemblyPath="System.Data" />
<AssemblyReference AssemblyPath="System.Windows.Forms" />
<AssemblyReference AssemblyPath="System.Xml" />
<AssemblyReference AssemblyPath="Microsoft.SqlServer.ManagedDTS.dll" />
<AssemblyReference AssemblyPath="Microsoft.SqlServer.ScriptTask.dll" />
</AssemblyReferences>
</ScriptTaskProject>
</ScriptProjects>
</Biml>