问题描述
我正在开发一个控制台应用程序,我正在从 C# 执行 SSIS 包。
下面是我的执行代码
private bool ExecutePackage(int _sid,int _pid,int _envid,string _connection,int _scheduleId)
{
bool isSuccess = false;
try
{
var dtPackagePath = HandlerFunctions.GetPackageInformation(_sid,_pid,_envid);
var DtsxPath = dtPackagePath.Rows[0]["dtsx_path"].ToString();
Application app = new Application();
Package package = null;
//Load the SSIS Package which will be executed
package = app.LoadPackage(DtsxPath,null);
//Pass the varibles into SSIS Package
package.Variables["User::mEnvID"].Value = _envid;
package.Variables["User::mPID"].Value = _projectid;
package.Variables["User::mSID"].Value = _sponsorid;
package.Variables["User::mConnectionString"].Value = _connection;
var results = package.Execute();
//Check the results for Failure and Success
if (results == DTSExecResult.Failure)
{
var err = "";
foreach (var localDtsError in package.Errors)
{
var error = localDtsError.Description;
err = err + error;
}
}
if (results == DTSExecResult.Success)
{
isSuccess = true;
}
}
catch (Exception ex)
{
isSuccess = false;
HandlerFunctions.WriteExceptionLog(_scheduleId,_sponsorid,_projectid,"Execute DTSX",ex.Message,ex.InnerException != null ? ex.InnerException.ToString() : string.Empty,ex.StackTrace,Convert.ToDateTime(DateTime.Now));
throw;
}
return isSuccess;
}
我在这个项目中引用了 Microsoft.Sqlserver.managedDTS.dll 并在 using 属性中使用了以下内容
using Microsoft.SqlServer.Dts.Runtime;
using Application = Microsoft.SqlServer.Dts.Runtime.Application;
我还在系统中使用 GACUTIL 注册了 ManagedDTS.dll。
但是,当我运行 porgram 时,我在 Application app = new Application(); 中遇到错误。错误如下
Unable to cast COM object of type 'Microsoft.SqlServer.Dts.Runtime.Wrapper.ApplicationClass' to interface type 'Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSApplication130'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{77A93073-6272-4FAC-BDB5-0C589385701C}' failed due to the following error: Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED)).
有人能帮我解决这个问题吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)