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

Script Task - Console.writeline alternative

$
0
0

I am using C# in the script task and i am using console.write line to show the message but when i execute the script task it doesn't show up any message but the package is running fine. How to pass the pop up message thru email task.

Do i need to use any other thing rather than the Console.writeline? Below is the c# code that i am using in the script task.How to send the  pop up message thru email task.

/*
   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 System.IO;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;


namespace ST_f80997887008481d8a35ab47884624e9.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

        /*
		The execution engine calls this method when the task executes.
		To access the object model, use the Dts property. Connections, variables, events,
		and logging features are available as members of the Dts property as shown in the following examples.

		To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value;
		To post a log entry, call Dts.Log("This is my log text", 999, null);
		To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true);

		To use the connections collection use something like the following:
		ConnectionManager cm = Dts.Connections.Add("OLEDB");
		cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;";

		Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
		
		To open Help, press F1.
	*/

        public void Main()
        {
            int counter = 0;
            string line;
            string filepath = "C:\\Users\\draghavendra\\Desktop\\EPS_INBOUND_ENROLLMENT.txt";
                                // = (string)(Dts.Variables["strFilePath"].Value) ;
            System.IO.FileInfo MyFile = new System.IO.FileInfo(filepath);
            if (MyFile.Exists)
            {
                // Read the file and display it line by line.
                System.IO.StreamReader file = new System.IO.StreamReader(filepath);

                while (!file.EndOfStream)
                {
                    line = file.ReadLine();
                    counter++;

                    //check if line is Empty
                    if (line.Length == 0)
                    {
                        System.Console.WriteLine("Empty File");
                        break;
                    }
                    //check if the first row is the Header
                    if (counter == 1 && !line.StartsWith("10"))
                    {
                        System.Console.WriteLine("No Header Record");
                        break;
                    }
                    //check for presence of any detail records
                    if (counter > 1 && (!file.EndOfStream) && (!line.StartsWith("20")))
                    {
                        System.Console.WriteLine("No Detail Records");
                        break;
                    }

                    //if (counter > 1 && (!line.StartsWith("20"))
                    //{
                    //    if ((counter <= 1) || (!line.StartsWith("20")))
                    //    {
                    //        System.Console.WriteLine("No Detail Records");
                    //    }

                    //}
                    //check if the last row is the Trailer
                    if (file.EndOfStream && !line.StartsWith("90"))
                    {
                        System.Console.WriteLine("No Trailer Record");
                        break;
                    }

                    //check for Total Records mismatch
                    if (file.EndOfStream && line.StartsWith("90"))
                    {
                        int totalRecords = int.Parse(line.Substring(11, 1));
                        int detailRecords = int.Parse(line.Substring(line.Length - 1));
                        if (counter != totalRecords)
                        {
                            System.Console.WriteLine("Mismatch in Total record count");
                            break;
                        }
                        if (counter != totalRecords)
                        {
                            System.Console.WriteLine("Mismatch in Detail record count");
                            break;
                        }
                    }
                }
            }
            else
            {
                System.Console.WriteLine("File Does not Exist");
            }
            //System.Console.ReadKey();

            
            
            
            Dts.TaskResult = (int)ScriptResults.Success;
        }
    }
}




Viewing all articles
Browse latest Browse all 24688

Trending Articles