2

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

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

4

2 回答 2

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 包生成脚本任务。

感谢比尔的回答。

于 2017-03-17T18:40:54.740 回答
0

当您将 VS2017 与 SSDT 一起使用并安装最新(预览)版本的 BimlExpress 2018 时,它可以正常工作。

与 VS2015 有同样的问题,升级到新版本的 BimlExpress 修复了它。

于 2018-05-14T15:36:18.180 回答