C#中调用SSIS包的问题

我用c#调用SSIS包来更新cube数据时总是提示如下错误:
The package failed to load due to error 0xC0011008 "Error loading from XML. No further detailed error information can be specified for this problem because no Events object was passed where detailed error information can be stored.".
This occurs when CPackage::LoadFromXML fails.
环境vs2005 ,sql server2008
代码如下:
public int ExecuteSSASDts()
{

//DtsRunTime.Application dtsApplication = new DtsRunTime.Application();
string filepath = "E:\\BACH\\QTY\\MM\\GSCS\\MainSource\\NewSource\\Web\\Dashboard\\Package.dtsx";
if (!System.IO.File.Exists(filepath))
{
return 2;
}
// Call SSIS package from SQL Server.
Microsoft.SqlServer.Dts.Runtime.Application application = new Microsoft.SqlServer.Dts.Runtime.Application();
Package package = application.LoadPackage(filepath, null); //运行到这句就包上面的错误
DTSExecResult result = package.Execute();
if (result.Equals(DTSExecResult.Success))
{
return 1;
}
else
{
return 0;
}
}

 

感谢几位的帮忙,问题找到了,是因为dll应用的问题,
因为cube是在sql server2008中,所以我的包是用2008写的,代码又是2005的,那我在代码引用DLL的时候引用的是Microsoft.SQLServer.DTSRuntimeWrap.dll 版本 9.0.240.0
代码中的属性与方法也是用的9.0.240.0 版本的,所以报错
解决方法:
删除web.config中9.0.240.0 版本的引用
重新引用10.0.0.0版本dll,如下:



代码调整部分:
改动前:
public int ExecuteSSASDts()
{
Application app = new Application();
//DTS包所在位置
String strDtsFilePath = //包的位置
if (!System.IO.File.Exists(strDtsFilePath))
{
return 2;
}
//处理包
Package package = app.LoadPackage(strDtsFilePath, null);
DTSExecResult result = package.Execute();
if (result == DTSExecResult.Success)
{
return 1;
}
else
{
return 0;
}
}
修改后代码:
public int ExecuteSSASDts()
{
string filepath = \\包的位置
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;
}
}
这个问题困扰了我好久,现发出来与大家共享,希望能给一些想我一样的菜鸟一些帮助

posted @ 2013-02-28 13:17  Nina  阅读(1941)  评论(2编辑  收藏  举报