Sql server 通过命令行以用户输入为变量运行SSIS包
我想将文件从一个位置移动到另一个位置,在我的SSIS包中,我在文件系统任务中设置了源。我创建了一个名为Path的变量,它是 C:\Users\VishalJethwa\Documents\Projects\Batch File SSIS Package Executer\ 还有一个名为Destination的空变量(它将是cmd中设置的文件夹名称),最后是一个完整路径变量,它将两者连接在一起,形成文件系统任务中的Destination属性。我尝试了以下方法,以便用户输入他们想要将文件移动到的文件夹名称,但似乎不起作用。我得到了错误 ,这是错误消息Microsoft(R)SQL Server执行包实用程序 版本10.50.1600.1,适用于64位 版权所有(C)微软公司2010。版权所有 开始时间:13:55:48 错误:2014-02-04 13:55:48.81 代码:0xC002F304 源:移动文件系统任务 描述:出现错误,错误消息如下:“无法执行f” ind文件'C:\Users\VishalJethwa\Documents\Projects\Batch file SSIS Package Execu ter\Source\Plank.txt.”。 端错误 进度:2014-02-04 13:55:48.81 来源:移动文件 操作完成:100%完成 结束进程 警告:2014-02-04 13:55:48.81 代码:0x80019002 来源:移动文件 说明:SSIS警告代码DTS_W_已达到最大错误计数。行刑 方法成功,但引发的错误数(1)已达到允许的最大值 教育署(1);导致失败。当错误数达到最大值时会发生这种情况 在MaximumErrorCount中指定的数字。更改最大错误计数或修复e 错误。 结束警告 警告:2014-02-04 13:55:48.81 代码:0x80019002 来源:BatchFileTest 说明:SSIS警告代码DTS_W_已达到最大错误计数。行刑 方法成功,但引发的错误数(1)已达到允许的最大值 教育署(1);导致失败。当错误数达到最大值时会发生这种情况 在MaximumErrorCount中指定的数字。更改最大错误计数或修复e 错误。 结束警告 DTExec:包执行返回DTSER_失败(1)。 开始时间:13:55:48 完成时间:13:55:48 已用时间:0.125秒 “/SET”未被识别为内部或外部命令, 可操作的程序或批处理文件 下面是我的批处理文件中的代码Sql server 通过命令行以用户输入为变量运行SSIS包,sql-server,batch-file,ssis,Sql Server,Batch File,Ssis,我想将文件从一个位置移动到另一个位置,在我的SSIS包中,我在文件系统任务中设置了源。我创建了一个名为Path的变量,它是 C:\Users\VishalJethwa\Documents\Projects\Batch File SSIS Package Executer\ 还有一个名为Destination的空变量(它将是cmd中设置的文件夹名称),最后是一个完整路径变量,它将两者连接在一起,形成文件系统任务中的Destination属性。我尝试了以下方法,以便用户输入他们想要将文件移动到的文件
@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
有什么想法吗?你有三个问题
发布第一个
在等待回复我的评论时,我的主要假设是这是一个套管问题。SSIS包中的实体区分大小写
列出的代码试图将\package.Variables
的值设置为一个值。没有可用的软件包,只有软件包
因此,/SET“\Package.Variables[User::Destination].Value”;Loc
@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
您可能还希望在双引号下传递Loc
,除非它是DOS 8.3样式的名称
发布第二条
Loc
的使用将是文本字符串Loc。您需要使用变量%Loc%
第三期
您没有给Loc赋值。在DOS中,等号之间不能有空格
最终结果
我创建了一个示例包SetDestination,其中包含一个脚本任务,该任务只需通过OnInformation事件激发Destination的值。其中的代码非常简单
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;
}
然后我修改了你的批处理文件
@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
执行结果
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 . . .
Biml
对于那些在家中跟随的人,假设您安装了免费附加组件,下面的Biml将创建参考包。使用上面的批处理文件(带有正确的.dtsx位置和SQL Server版本)来调用它,您应该会得到与我相同的结果
<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>
运用系统反思;
使用System.Runtime.CompilerServices;
//
//有关部件的一般信息通过以下方式控制
//属性集。更改这些属性值以修改信息
//与程序集关联的。
//
[大会:大会名称(“ST_C41AD4BF47544C49AD46F440163FEAE.csproj”)]
[组装:组装说明(“”)]
[程序集:程序集配置(“”)]
[大会:大会公司(“Varigence”)]
[组装:组装产品(“ST_C41AD4BF47544C49AD46F440163FEAE.csproj”)]
[大会:大会版权所有(“版权@Varigence 2013”)]
[组装:组装商标(“”)]
[大会:大会文化(“”)
//
//程序集的版本信息由以下四个值组成:
//
//主要版本
//次要版本
//建筑编号
//修改
//
//您可以指定所有