如何在Script Task中访问RecordSet变量?
在SSIS中的脚本任务内部,我需要调用SQL数据库.我有一个连接字符串是在我将数据库添加到数据源文件夹时创建的,但是现在我不确定如何在C#代码中引用它.我知道如何在ASP网站的代码中执行此操作,但似乎SSIS应该有更直接的方法.
编辑
这行代码实际上最终会抛出异常:
sqlConn = (System.Data.SqlClient.SqlConnection)cm.AcquireConnection(Dts.Transaction);
Run Code Online (Sandbox Code Playgroud)
它写道:"无法将'System._ComObject'类型的COM对象强制转换为类类型'System.Data.SqlClient.SqlConection.'"
我发生了一个非常奇怪的问题,导致脚本任务代码清除.我已经能够在2-3种不同的机器上进行测试.我们正在运行SSDT 15.4预览.重现的步骤如下.
作为我成功的最后一次尝试,我已升级到15.5.1并且问题仍然存在.
我有一个带有脚本任务的SSIS包,当我尝试在我的本地系统中运行它时出现以下错误.它适用于我的同事和生产.但是,我无法在本地运行它来进行测试.我在main方法中保留了一个调试点,但它永远不会到达,我在进入main方法之前得到了错误.

我正在使用VS 2010,.Net framework 4.5.
脚本任务确实编译.我得到以下消息SSIS包"..\Test.dtsx"开始.错误:测试时为0x1:调用目标引发了异常.任务失败:测试SSIS包"..\Test.dtsx"完成:成功.程序'[2552] DtsDebugHost.exe:DTS'已退出代码0(0x0).
以下是代码:
public void Main()
{
try
{
LogMessages("Update Bug package execution started at :: " + DateTime.Now.ToLongTimeString());
LogMessages("Loading package configuration values to local variables.");
strDBConn = Dts.Variables["User::DBConnection"] != null ? Dts.Variables["User::DBConnection"].Value.ToString() : string.Empty;
strTPCUrl = Dts.Variables["User::TPCUrl"] != null ? Dts.Variables["User::TPCUrl"].Value.ToString() : string.Empty;
TfsTeamProjectCollection objTPC = new TfsTeamProjectCollection(new Uri(strTPCUrl));
WorkItemStore objWIS = new WorkItemStore(objTPC);
WorkItemCollection objWIC = objWIS.Query("SELECT...");
foreach (WorkItem wi in objWIC)
{
}
}
catch(Exception ex)
{
}
Run Code Online (Sandbox Code Playgroud)
当我评论来自TfsTeamProjectCollection的代码时objTPC = new TfsTeamProjectCollection(new …
我制作了以下 PowerShell 脚本:
Set-Location D:\folder1\folder2\folder3\folder4;
Get-ChildItem | Rename-Item -NewName {$_.BaseName.insert(19,'loadtime') + (Get-Date -Format HHmm) + $_.Extension};
Run Code Online (Sandbox Code Playgroud)
目标是通过在位置 19 添加加载时间和时间戳来重命名文件。运行脚本的结果返回以下错误消息:
Rename-Item : The input to the script block for parameter 'NewName' failed.
Exception calling "Insert" with "2" argument(s): "Specified argument was out
of the range of valid values.
Parameter name: startIndex"
At D:\folder1\folder2\folder3\folder4\folder5\RenameFile.ps1:2
char:38
+ Get-ChildItem | Rename-Item -NewName {$_.BaseName.insert(19,'loadtime') +
(Get-D ...
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Archive:PSObject) [Rename-
Item], ParameterBindingException
+ FullyQualifiedErrorId :
ScriptBlockArgumentInvocationFailed,
Microsoft.PowerShell.Commands.RenameItemCommand
Run Code Online (Sandbox Code Playgroud)
当我从 SSIS 包运行脚本时,出现以下错误: …
我使用EPPlus.dll库动态生成Excel文件以进行附件,并在SSIS包的脚本任务中生成邮件程序.
当邮件程序中有新的更改要求时,我在本地计算机上执行脚本任务更改,并将构建的包文件(.dtsx)发送给DBA团队进行部署.
现在每次我都要请DBA团队与我共享生产服务器屏幕,我在哪里:
然后,他们从MSDB中导入包文件,从那里调度作业引用并执行包.
如果我不执行上述步骤,则脚本任务会引发未找到引用的错误.
错误1找不到类型或命名空间名称'OfficeOpenXml'(您是否缺少using指令或程序集引用?)
我克服了在脚本任务中引用的GAC中安装DLL的挑战,方法是动态加载程序集,如下所示'
public void Main()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}
private System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
return System.Reflection.Assembly.LoadFrom(System.IO.Path.Combine(strDLLPath, "EPPlus.dll"));
}
Run Code Online (Sandbox Code Playgroud)
但我,无法找到避免手动浏览和添加DLL引用的步骤.请帮助,因为DBA团队不愿意/避免共享屏幕.
或者,如果我没有直接访问生产服务器,那么在使用外部dll的服务器上部署包文件的正确/最佳实践方法是什么.
我正在尝试使Microsoft.Azure.Services.AppAuthentication及其依赖项与 SSIS 脚本任务一起使用。如何解决程序集引用错误?
static ScriptMain()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name.Contains("Microsoft.Azure.Services.AppAuthentication"))
{
return System.Reflection.Assembly.LoadFile(@"C:\Azure\packages\Microsoft.Azure.Services.AppAuthentication.1.6.2\lib\net472\Microsoft.Azure.Services.AppAuthentication.dll");
}
if (args.Name.Contains("Microsoft.IdentityModel.Clients.ActiveDirectory"))
{
return System.Reflection.Assembly.LoadFile(@"C:\Azure\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.5.2.9\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll");
}
}
Run Code Online (Sandbox Code Playgroud) 我需要通过脚本任务连接到SQL Server数据库以填充a DataTable,我正在使用ADO.Net提供程序/连接.然而,对于我的生活,我遇到了各种各样的错误.例如,当使用SqlAdapter我得到无效的对象错误时,但是SqlCommand在SSMS中执行没有错误:
SqlConnection conn;
ConnectionManager cm;
SqlCommand cmd;
cm = Dts.Connections["AdoNet"];
conn = (SqlConnection)cm.AcquireConnection(Dts.Transaction);
using (conn)
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = queryString;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(myDataTable);
}
Run Code Online (Sandbox Code Playgroud) 我在 SSIS (2008) 包中有一个脚本任务,用于将文件从远程 FTP 服务器下载到本地目录。脚本任务是用 C# 2008 编写的,并使用 WinSCPnet.dll。使用 WinSCP 文档中的示例,我想出了下面的脚本。该脚本可以正确下载文件,但所有文件成功/失败消息都会保留,直到整个脚本完成,然后所有消息都会立即转储。使用 根本不显示文件进度Console.Write(),并且尝试使用Dts.Events.FireInformation()inSessionFileTransferProgress给了我
Error: "An object reference is required for the non-static field, method, or property Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase.Dts.get"
有没有办法使用 DTS.events.Fire* 事件来显示文件发生时的进度信息以及每个文件后的文件完成状态?
脚本:
/*
Microsoft SQL Server Integration Services Script Task
Write scripts using Microsoft Visual C# 2008.
The ScriptMain is the entry point class of the script.
*/
using System;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Tasks.ScriptTask;
using System.AddIn;
using WinSCP;
namespace ST_3a1cf75114b64e778bd035dd91edb5a1.csproj
{
[AddIn("ScriptMain", Version = "1.0", …Run Code Online (Sandbox Code Playgroud) 我需要使用脚本任务将数据从SQL任务中的数据获取到DataTable对象,以生成电子邮件。但是,当我尝试使用OLEDB适配器填充任务填充数据时,会生成错误:
OleDbDataAdapter内部错误:无效的行集访问器:Ordinal = 1 Status = UNSUPPORTEDCONVERSION
屏幕截图
如上,
public void Main()
{
// TODO: Add your code here
DataTable dt = new DataTable();
String message = "";
OleDbDataAdapter adapter = new OleDbDataAdapter();
if (Dts.Variables.Contains("onErrorList") == true)
{
try
{
try
{
adapter.Fill(dt, Dts.Variables["onErrorList"].Value);
} catch (Exception e)
{
MessageBox.Show(e.Message);
}
foreach (DataRow row in dt.Rows)
{
message = message + "\n" + "Error Time : " + row["message_time"] + "\n" + "Execution Path : " + row["executionpath"] + "\n" …Run Code Online (Sandbox Code Playgroud) script-task ×10
ssis ×10
c# ×6
sql-server ×5
etl ×4
ado.net ×1
dll ×1
oledb ×1
powershell ×1
scripting ×1
sql ×1
ssis-2008 ×1
variables ×1
winscp-net ×1