Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Error in script task c#

$
0
0

Hi, since last two days i tried to run package but i got stuck with one error only. In script task my file path is my source file. It catch that file which is not exists in that folder. My file path is \\sss0000111\Unit-B\Test\CSV. Error is \\sss0000111\Unit-B\Test\CSV_SUM. It tries to catch CSV_SUM file which doesn't exist in Test folder. I am stuck with this and i dont know how to solve this. File path is variable in my C# script. Please guide me for this. 

using System;

using System.IO;

using System.Text;

using System.Data;

//using System.Math;

using Microsoft.SqlServer.Dts.Runtime;

 

namespace ST_8b99b23ffd944c6abe15bca3437320d8.csproj

{

    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]

    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

    {

 

        #region VSTA generated code

        enum ScriptResults

        {

            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,

            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure

        };

        #endregion

 

        public void Main()

        {

            Dts.TaskResult = (int)ScriptResults.Success;

            Boolean fireagain = false;

            int taskResult;

            string fileSourcePath;

            string fileDestPath;

            StreamReader sr;

            StreamWriter sw;

            string Str;

            string delim = ",";

            string RecordType;

            //         Dim FileCreateDate As Date

            string LastRecordType = "   ";

            string FilesProcessed;

            string SourceFileName;

            string CurrentDate;

            string FileName;

 

 

 

 

 

 

 

 

            // Dim ret As Integer

            CurrentDate = DateTime.Now.ToString("yyyyMMdd");

            Dts.Events.FireInformation(-1, "CurrentDate", CurrentDate.ToString(),String.Empty, 0, ref fireagain);

 

            try

            {

               fileSourcePath = Dts.Variables["User::FilePath"].Value.ToString();

                fileDestPath = Dts.Connections["CGDP_RECON"].ConnectionString.ToString();

                FilesProcessed = Dts.Variables["User::FilesProcessed"].Value.ToString();//FilesProcessed

                FileName = Dts.Variables["User::FileName"].Value.ToString();

                //fileSourcePath = ReadVariable("FilePath").ToString(); //FilePath

                //fileDestPath = Dts.Connections["CGDP_INPUT.csv"].ConnectionString.ToString();

                //FilesProcessed = ReadVariable("FilesProcessed").ToString();//FilesProcessed

 

                //the value before we change it here

                Dts.Events.FireInformation(-1, "fileSourcePath", fileSourcePath, String.Empty, 0, ref fireagain);

                Dts.Events.FireInformation(-1, "FileName", FileName, String.Empty, 0, reffireagain);

                //  Dim valid As Boolean

                //  Dim fileID As String

                //  Dim contract As String

                int sep;

                sep = FileName.LastIndexOf("\\");//fileSourcePath.LastIndexOf("\\");

               

                

                SourceFileName = FileName.Substring((sep + 1));//fileSourcePath.Substring((sep + 1));

                Dts.Events.FireInformation(-1, "SourceFileName", SourceFileName, String.Empty, 0, ref fireagain);

 

                sr = File.OpenText(fileSourcePath+FileName);//File.OpenText(fileSourcePath);

                //string test = Dts.Variables[sr].Value.ToString();

 

                Str = sr.ReadLine();

 

                Dts.Variables[Str].Value.ToString();


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>