Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

Sankar

@Carlos Letona: Thank you. Your method worked.
Carlos Letona

Re: Unable to use new SessionOptions statement in SSIS Script Task

I was getting the same exception error, but I just added a static script. By loading the path of the WinSCP.dll, and it worked.
static ScriptMain()
{
    AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}
 
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    if (args.Name.Contains("WinSCPnet"))
    {
        string path = @"C:\Program Files (x86)\WinSCP";
        return Assembly.LoadFile(Path.Combine(path, "WinSCPnet.dll"));
    }
    return null;
}
joerobbi

Re: Unable to use new SessionOptions statement in SSIS Script Task

That's part of what's killing me; I can't seem to trap an exception from the Script task. Try/Catch and full logging for that task give the error log below.

I admit I'm no expert, so if there's another way to catch that inner exception, I'm all ears. :-)
------------Error Log---------------

OnPreValidate,ServerName,Domain\User,Script_Download,{199F7AF1-A521-4E98-9596-0FD4B91E3FFF},{222A4A31-33C8-48FC-A176-B8663227477E},1/25/2018 8:45:23 AM,1/25/2018 8:45:23 AM,0,0x,
OnPostValidate,ServerName,Domain\User,Script_Download,{199F7AF1-A521-4E98-9596-0FD4B91E3FFF},{222A4A31-33C8-48FC-A176-B8663227477E},1/25/2018 8:45:23 AM,1/25/2018 8:45:23 AM,0,0x,
OnError,ServerName,Domain\User,Script_Download,{199F7AF1-A521-4E98-9596-0FD4B91E3FFF},{222A4A31-33C8-48FC-A176-B8663227477E},1/25/2018 8:45:24 AM,1/25/2018 8:45:24 AM,1,0x,Exception has been thrown by the target of an invocation.
OnTaskFailed,ServerName,Domain\User,Script_Download,{199F7AF1-A521-4E98-9596-0FD4B91E3FFF},{222A4A31-33C8-48FC-A176-B8663227477E},1/25/2018 8:45:24 AM,1/25/2018 8:45:24 AM,0,0x,
OnPostExecute,ServerName,Domain\User,Script_Download,{199F7AF1-A521-4E98-9596-0FD4B91E3FFF},{222A4A31-33C8-48FC-A176-B8663227477E},1/25/2018 8:45:24 AM,1/25/2018 8:45:24 AM,0,0x,
martin

Re: Unable to use new SessionOptions statement in SSIS Script Task

The exception has an inner exception for sure. What is it?
joerobbi

Unable to use new SessionOptions statement in SSIS Script Task

I'm attempting to use the WinSCP assembly for the first time in SSIS, and I can't seem to get it to work (code below). The Script task fails each time with that useless "Exception has been thrown by the target of an invocation" error. Starting at the bottom and incrementally commenting out code, it doesn't start running until I comment out the SessionOptions soOpt = new SessionOptions lines. WinSCP is installed, and I've added the assembly as a Reference on the task, but no joy. Any help would be very much appreciated!

Actual Code (servers/filenames redacted):
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using WinSCP;
 
public void Main()
{
    SessionOptions soOpt = new SessionOptions
    {
        Protocol = Protocol.Sftp
        ,SshHostKeyFingerprint = "ssh-rsa 2048 00:00..."
        ,HostName = "server.company.com"
        ,UserName = "UserName"
        ,SshPrivateKeyPath = @"X:\Directory\Key_Private.ppk"
    };
    using (Session seNew = new Session())
    {
        seNew.ExecutablePath = @"E:\Program Files (x86)\WinSCP\winscp.exe";
        seNew.Open(soOpt);
        TransferOptions xfrOptions = new TransferOptions();
        xfrOptions.TransferMode = TransferMode.Binary;
        TransferOperationResult xfrResult;
        xfrResult = seNew.GetFiles(@"/home/UserName/file.txt", @"X:\Directory\file.txt", false, xfrOptions);
        xfrResult.Check();
    }
}