I am working on a Console application where I am executing a SSIS package from c#.
Below is my code for the execution
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;
}
I have referenced Microsoft.Sqlserver.managedDTS.dll with this project and used the below in using attribute
using Microsoft.SqlServer.Dts.Runtime;
using Application = Microsoft.SqlServer.Dts.Runtime.Application;
I have also registered the ManagedDTS.dll using the GACUTIL in the system.
However, when i run the porgram I am getting error in the Application app = new Application(); and the error is as below
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)).
Can anyone help me with this issue?