using System;
using System.Windows.Forms;
using Microsoft.SqlServer.Dts.Runtime;
using Application = System.Windows.Forms.Application;
private void Execute_Package()
{
string pkgLocation = @"c:\test.dtsx";
Package pkg;
Application app;
DTSExecResult pkgResults;
Variables vars;
app = new Application();
pkg = app.LoadPackage(pkgLocation, null);
vars = pkg.Variables;
vars["A_Variable"].Value = "Some value";
pkgResults = pkg.Execute(null, vars, null, null, null);
if (pkgResults == DTSExecResult.Success)
Console.WriteLine("Package ran successfully");
else
Console.WriteLine("Package failed");
}
pkg = app.LoadPackage(pkgLocation, null); <-- LoadPackage error
我将此示例复制到vs2013中添加了引用,我在LoadPackage
行收到错误:
does not contain a definition for 'LoadPackage' and no extension
method 'LoadPackage' accepting a first argument of type
'System.Windows.Forms.Application' could be found (are you missing a
using directive or an assembly reference?
我需要添加另一个参考吗?我正在使用谷歌搜索,但没有找到。也许我只是累了。请帮忙。
答案 0 :(得分:1)
变化:
using Microsoft.SqlServer.Dts.Runtime;
using Application = System.Windows.Forms.Application;
为:
using Microsoft.SqlServer.Dts.Runtime;
using Application = Microsoft.SqlServer.Dts.Runtime.Application;
答案 1 :(得分:0)
您是否尝试过从代码中运行DTEXEC实用程序。这就是我一直以来做的事情。
对不起,我不能提供一个例子,目前我在手机上。
答案 2 :(得分:0)
好的问题是我使用了错误的语句。
我正在使用Application = System.Windows.Forms.Application; 我应该使用Application = Microsoft.SqlServer.Dts.Runtime.Application
一位工作的朋友发现了这个问题。