为什么BIML ScriptTask失败,直到我在VS中打开脚本并保存包

时间:2017-03-16 19:19:08

标签: ssis script-task biml

我有这个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>

我错过了什么?为什么在我手动打开代码窗口之前包失败? 在此先感谢您的帮助, 西蒙

2 个答案:

答案 0 :(得分:5)

阅读上述评论以澄清问题。

事实证明,Visual Studio 2015中的BIML Express / BidsHelper不知道在Project属性中设置了哪个SQL Server目标版本。

解决方案是安装VS2013 / SSDT 2014,BIML Express for VS2013能够正确生成SSIS 2014软件包。

VS 2015 / SSDT / BIML Express将仅为SQL Server SSIS 2016包生成脚本任务。

感谢比尔的回答。

答案 1 :(得分:0)

当您使用带有SSDT的VS2017并安装最新(预览版)的BimlExpress 2018时,它正在工作。

VS2015遇到同样的问题并升级到新版本的BimlExpress修复了它。