首先,引用10.0.0.0版本dll,如下:
<add assembly="Microsoft.SqlServer.Dts.Design, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
<add assembly="Microsoft.SqlServer.DTSPipelineWrap, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
<add assembly="Microsoft.SqlServer.DTSRuntimeWrap, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/></assemblies>
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
代码如下:
public int ExecuteSSASDts()
{
string filepath = urlconvertorlocal("Package.dtsx");
if (!System.IO.File.Exists(filepath))
{
return 2;
}
// Call SSIS package from SQL Server.
Application application = new ApplicationClass();
IDTSPackage100 package = application.LoadPackage(filepath,false,null);
DTSExecResult result = package.Execute();
if (result.Equals(DTSExecResult.DTSER_SUCCESS))
{
return 1;
}
else
{
return 0;
}
}
//相对路径转换成服务器本地物理路径
private string urlconvertorlocal(string imagesurl1)
{
string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//获取程序根目录
string imagesurl2 = tmpRootDir + "//Dashboard//" + imagesurl1.Replace(@"/", @"/"); //转换成绝对路径
return imagesurl2;
}