问题描述
我正在开发一个控制台应用程序,我正在从 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)).
有人能帮我解决这个问题吗?
解决方法
问题有两个方面。第一个是您正在尝试为集成服务零碎地复制 DLL,这不是安装程序将如何处理它。您需要重现 SQL Server 安装程序的所有相同操作,以使 SSIS 在客户端计算机上进入工作状态。
更大的问题是,您尝试做的事情违反了许可协议。您有权免费开发 SSIS 包。除非该服务器已获得 SQL Server 的许可,否则您无权运行 SSIS 包。即使您设法解决了第一个问题,您也已经创建了一个解决方案,使您的雇主或客户承担来自 Microsoft 许可的法律责任,这不会是一个廉价的解决方案。不是 Oracle 许可数量级差,但仍然不愉快。
要使开发者机器进入正确状态,您需要获取 SQL Server 开发者版的副本。在实例功能屏幕上,选择 “集成服务”
这将确保所有正确的程序集都安装在他们希望找到的地方。
,根据错误,您运行此程序的机器似乎没有安装 SQL Server 集成服务。
您需要 SSIS 才能运行 SSIS 包! (You can't run SSIS packages without SSIS)
您不需要复制/注册 DLL,您应该尝试引用 SQL Server 安装程序安装的 C# 程序集。
在我的机器上,我可以在这个位置看到 C# 程序集: