我有这个 BIML 脚本,它创建了一个主包和子包。子包中有一个 ScriptTask,它将父包变量的值映射到子包变量。当我在 SSIS(Visual Studio 2015,目标 Sql Server 2014)中生成包时,它们生成得很好。如果我运行主包,孩子会失败并出现以下错误:
DTS Script Task has encountered an exception in user code:
Project name: ST_GetJobLogIdHere
Exception has been thrown by the target of an invocation.
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
当我在孩子中打开 ScriptTask,然后再次关闭它时,包很脏,所以我保存了它。之后,运行包正常工作。
这是BIML脚本:
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
<ScriptProjects>
<ScriptTaskProject ProjectCoreName="ST_GetJobLogId" Name="ST_GetJobLogIdScript" VstaMajorVersion="0">
<ReadOnlyVariables>
<Variable Namespace="User" VariableName="vMasterJobLogId" DataType="Int32" />
</ReadOnlyVariables>
<ReadWriteVariables>
<Variable Namespace="User" VariableName="vJobLogId" DataType="Int32" />
</ReadWriteVariables>
<AssemblyReferences>
<AssemblyReference AssemblyPath="Microsoft.SqlServer.ManagedDTS" />
<AssemblyReference AssemblyPath="Microsoft.SqlServer.ScriptTask" />
<AssemblyReference AssemblyPath="System" />
<AssemblyReference AssemblyPath="System.Data" />
<AssemblyReference AssemblyPath="System.Windows.Forms" />
<AssemblyReference AssemblyPath="System.Xml" />
</AssemblyReferences>
<Files>
<File Path="AssemblyInfo.cs" BuildAction="Compile">
using System.Reflection;
[assembly: AssemblyTitle("ST_GetJobLogId")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ST_GetJobLogId")]
[assembly: AssemblyCopyright("Copyright @ BMI 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.*")]
</File>
<File Path="ScriptMain.cs" BuildAction="Compile">
using Microsoft.SqlServer.Dts.Runtime;
namespace ST_GetJobLogId
{
[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPoint]
public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
{
public void Main()
{
int jobLogId = (int)Dts.Variables["User::vMasterJobLogId"].Value;
if (jobLogId != 0)
Dts.Variables["User::vJobLogId"].Value = jobLogId;
Dts.TaskResult = (int)ScriptResults.Success;
}
enum ScriptResults
{
Success = DTSExecResult.Success,
Failure = DTSExecResult.Failure
};
}
}
</File>
</Files>
</ScriptTaskProject>
</ScriptProjects>
<Packages>
<Package Name="Master" ProtectionLevel="EncryptSensitiveWithUserKey">
<Variables>
<Variable Name="vMasterJobLogId" DataType="Int32">1</Variable>
</Variables>
<Tasks>
<ExecutePackage Name="PKG - Execute FixMe">
<ExternalProjectPackage Package="FixMe.dtsx" />
</ExecutePackage>
</Tasks>
</Package>
<Package Name="FixMe" ProtectionLevel="EncryptSensitiveWithUserKey">
<Variables>
<Variable Name="vJobLogId" DataType="Int32">0</Variable>
</Variables>
<Tasks>
<Script Name="SCR - Get vJobLogId from parent vMasterJobLogId" ProjectCoreName="ST_GetJobLogIdHere" >
<ScriptTaskProjectReference ScriptTaskProjectName="ST_GetJobLogIdScript" />
</Script>
</Tasks>
</Package>
</Packages>
</Biml>
我错过了什么?为什么在我手动打开代码窗口之前包会失败?提前感谢您的帮助,西蒙