简体   繁体   中英

“Cannot execute script because the script entry point is invalid” error in script task in SSIS

I am trying to upload files from my local folder to SFTP using SSIS Script Task. On replicating the script from https://winscp.net/eng/docs/library#csharp I get an error

Error: Cannot execute script because the script entry point is invalid.

Below is the complete script:

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using WinSCP;

namespace ST_1ae95a63b20641ffb8ed1769503e2841
{
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {
        #region Help:  Using Integration Services variables and parameters in a script
        class upload
        {
            public static int Main()
            {
                try
                {
                    SessionOptions sessionOptions = new SessionOptions
                    {
                        Protocol = Protocol.Sftp,
                        HostName = "a.com",
                        UserName = "btest",
                        Password = "c",
                        SshHostKeyFingerprint = "ssh-rsa 2048 avc",
                    };

                    using (Session session = new Session())
                    {
                        // Connect
                        session.Open(sessionOptions);

                        // Upload files
                        TransferOptions transferOptions = new TransferOptions();
                        transferOptions.TransferMode = TransferMode.Binary;

                        TransferOperationResult transferResult;
                        transferResult =
                            session.PutFiles(@"d:\abc\efdg\*", "/cvf/pqr/", false, transferOptions);

                        // Throw on any error
                        transferResult.Check();

                        // Print results
                        foreach (TransferEventArgs transfer in transferResult.Transfers)
                        {
                            Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
                        }
                    }

                    return 0;
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: {0}", e);
                    return 1;
                }
            }
        }
    }
}

I would appreciate if someone can help me with this error.

As WinSCP example for SSIS shows , the signature should be like:

[AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
public partial class ScriptMain : VSTARTScriptObjectModelBase
{
    public void Main()
    {
        // ...
    }
}

Particularly, remove the nested upload class.

According to this Msdn article :

Make sure in the script task's editor, the Script page's Entry Point property is set to ScriptMain.

在此输入图像描述

Additional Informations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM