首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >以用户输入为变量,通过命令行运行SSIS包

以用户输入为变量,通过命令行运行SSIS包
EN

Stack Overflow用户
提问于 2014-02-04 13:50:26
回答 2查看 3.9K关注 0票数 0

我想将文件从一个位置移动到另一个位置,在我的SSIS包中,我在文件系统任务中设置了源代码。我已经创建了一个名为Path的变量,它是

C:\Users\VishalJethwa\Documents\Projects\Batch文件SSIS包执行程序\

和一个名为目的地的空白变量(它将是在cmd中设置的文件夹名),最后是一个完整的路径变量,它将这两个变量连接在一起,以在文件系统任务中形成目标属性。我尝试了下面的方法,以便用户输入他们想要将文件移动到的文件夹名,但是它似乎不起作用。我知道错误了

,这是错误消息-- Microsoft (R) SQL Server执行软件包实用程序版本10.50.1600.1,用于64位版权(C) Microsoft Corporation 2010。版权所有。

开始: 13:55:48错误: 2014-02-04 13:55:48.81代码: 0xC002F304源代码::出现以下错误信息:“following文件'C:\Users\VishalJethwa\Documents\Projects\Batch文件\Source\Plank.txt‘”。结束错误进度: 2014-02-04 13:55:48.81来源:移动文件操作完成: 100%完成结束进度警告: 2014-02-04 13:55:48.81代码: 0x80019002来源:移动文件描述: SSIS警告代码DTS_W_MAXIMUMERRORCOUNTREACHED。执行方法成功,但引发的错误数(1)达到允许ed (1)的最大值,从而导致失败。当错误数达到MaximumErrorCount中指定的数目时,就会发生这种情况。更改MaximumErrorCount或修复错误。最后警告警告: 2014-02-04 13:55:48.81代码: 0x80019002资料来源: BatchFileTest描述: SSIS警告代码DTS_W_MAXIMUMERRORCOUNTREACHED。执行方法成功,但引发的错误数(1)达到允许ed (1)的最大值,从而导致失败。当错误数达到MaximumErrorCount中指定的数目时,就会发生这种情况。更改MaximumErrorCount或修复错误。结束警告DTExec:包执行返回DTSER_FAILURE (1)。开始: 13:55:48完成: 13:55:48已过: 0.125秒/集不被识别为内部或外部命令、可操作的程序或批处理文件。

下面是批处理文件中的代码

代码语言:javascript
运行
复制
@ECHO OFF
SET /p Loc = What folder do you wish to copy it to?: 
DTEXEC /FILE "C:\Users\Admin\Documents\Projects\Batch File SSIS Package Executer\BatchFileTest\BatchFileTest\BatchFileTest.dtsx" 
/SET "\package.Variables[User::Destination].Value";Loc
pause

有什么想法吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-04 13:56:04

你有三个问题。

第一次发行

在等待对我的评论作出回应时,我的主要假设是,这是一个套管问题。SSIS包中的实体区分大小写。

列出的代码试图将\package.Variables的值设置为值。没有可用的包,只有包

因此,/SET "\Package.Variables[User::Destination].Value";Loc

您可能也希望在双引号下传递Loc,除非它将是DOS8.3风格的名称。

第二次发行

Loc的使用将是文字字符串Loc。您需要使用变量%Loc%

第三次发行

您没有将值分配给Loc。在DOS中,在等号之间不能有空格

最终结果

我创建了一个示例包SetDestination,其中包含一个脚本任务,它只会激发OnInformation事件的目标值。里面的代码很简单

代码语言:javascript
运行
复制
    public void Main()
    {
        bool fireAgain = false;
        Dts.Events.FireInformation(0, "emit", string.Format("Destination: {0}", Dts.Variables[0].Value.ToString()), string.Empty, 0, ref fireAgain);
        Dts.TaskResult = (int)ScriptResults.Success;
    }

然后我修改了您的批处理文件如下

代码语言:javascript
运行
复制
@ECHO OFF
set loc=unset
SET /p Loc=What folder do you wish to copy it to?:
"C:\Program Files (x86)\microsoft sql server\110\dts\binn\dtexec.exe" /FILE "C:\Users\bfellows\Documents\Visual Studio 2012\Projects\SSISPOC\PackageDeploymentModel\SetDestination.dtsx"  /SET "\Package.Variables[User::Destination].Value";"%Loc%" /rep i
pause

执行结果

代码语言:javascript
运行
复制
What folder do you wish to copy it to?:Stuff
Microsoft (R) SQL Server Execute Package Utility
Version 11.0.3401.0 for 32-bit
Copyright (C) Microsoft Corporation. All rights reserved.

Started:  8:23:15 AM
Info: 2014-02-04 08:23:15.84
   Code: 0x00000000
   Source: SCR Emit emit
   Description: Destination: Stuff
End Info
DTExec: The package execution returned DTSER_SUCCESS (0).
Started:  8:23:15 AM
Finished: 8:23:15 AM
Elapsed:  0.188 seconds
Press any key to continue . . .

比姆尔

对于那些在家中跟随的人,假设您已经安装了免费的投标帮手 add,下面的Biml将创建这个参考包。使用上面的批处理文件(带有更正的.dtsx位置和Server版本)来调用它,您应该得到与我相同的结果。

代码语言:javascript
运行
复制
<Biml xmlns="http://schemas.varigence.com/biml.xsd">
    <Packages>
        <Package Name="SetDestination" ConstraintMode="Parallel" ProtectionLevel="DontSaveSensitive">
            <Variables>
                <Variable DataType="String" Name="Destination"></Variable>
            </Variables>
            <Tasks>
                <Script ProjectCoreName="ST_232fecafb70a4e8a904cc21f8870eed0" Name="SCR Emit Destination">
                    <ReadOnlyVariables>
                        <ReadOnlyVariable VariableName="User.Destination" />
                    </ReadOnlyVariables>
                    <ScriptTaskProject>
                        <ScriptTaskProject ProjectCoreName="ST_c41ad4bf47544c49ad46f4440163feae" Name="TaskScriptProject1">
                            <AssemblyReferences>
                                <AssemblyReference AssemblyPath="Microsoft.SqlServer.ManagedDTS.dll" />
                                <AssemblyReference AssemblyPath="Microsoft.SqlServer.ScriptTask.dll" />
                                <AssemblyReference AssemblyPath="System.dll" />
                                <AssemblyReference AssemblyPath="System.AddIn.dll" />
                                <AssemblyReference AssemblyPath="System.Data.dll" />
                                <AssemblyReference AssemblyPath="System.Windows.Forms.dll" />
                                <AssemblyReference AssemblyPath="System.Xml.dll" />
                            </AssemblyReferences>
                            <Files>
                                <File Path="AssemblyInfo.cs">
                                    using System.Reflection;
                                    using System.Runtime.CompilerServices;

                                    //
                                    // General Information about an assembly is controlled through the following
                                    // set of attributes. Change these attribute values to modify the information
                                    // associated with an assembly.
                                    //
                                    [assembly: AssemblyTitle("ST_c41ad4bf47544c49ad46f4440163feae.csproj")]
                                    [assembly: AssemblyDescription("")]
                                    [assembly: AssemblyConfiguration("")]
                                    [assembly: AssemblyCompany("Varigence")]
                                    [assembly: AssemblyProduct("ST_c41ad4bf47544c49ad46f4440163feae.csproj")]
                                    [assembly: AssemblyCopyright("Copyright @ Varigence 2013")]
                                    [assembly: AssemblyTrademark("")]
                                    [assembly: AssemblyCulture("")]
                                    //
                                    // Version information for an assembly consists of the following four values:
                                    //
                                    //      Major Version
                                    //      Minor Version
                                    //      Build Number
                                    //      Revision
                                    //
                                    // You can specify all the values or you can default the Revision and Build Numbers
                                    // by using the '*' as shown below:

                                    [assembly: AssemblyVersion("1.0.*")]
                                </File>
                                <File Path="ScriptMain.cs">
                                    using System;
                                    using System.Data;
                                    using Microsoft.SqlServer.Dts.Runtime;
                                    using System.Windows.Forms;

                                    // if SSIS2012, use the following line:
                                    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]

                                    // if earlier version, use the next line instead of the above line:
                                    // [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
                                    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
                                    {
                                    enum ScriptResults
                                    {
                                    Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
                                    Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
                                    };

                                    public void Main()
                                    {
                                    bool fireAgain = false;
                                    Dts.Events.FireInformation(0, "emit", string.Format("Destination: {0}", Dts.Variables[0].Value.ToString()), string.Empty, 0, ref fireAgain);
                                    Dts.TaskResult = (int)ScriptResults.Success;
                                    }
                                    }
                                </File>
                            </Files>
                        </ScriptTaskProject>
                    </ScriptTaskProject>
                </Script>
            </Tasks>
        </Package>
    </Packages>
</Biml>
票数 4
EN

Stack Overflow用户

发布于 2014-02-04 14:15:06

我想你错过了%Loc

代码语言:javascript
运行
复制
@ECHO OFF
SET /p Loc = What folder do you wish to copy it to?: 
DTEXEC /FILE "C:\Users\Admin\Documents\Projects\Batch File SSIS Package Executer\BatchFileTest\BatchFileTest\BatchFileTest.dtsx" 
/SET "\package.Variables[User::Destination].Value";"%Loc%"
pause

正如billinkc所说,如果您发送包含空格的位置,将它们放在""中会有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21554352

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档