Teradata connection in SSIS script task c#

deepak grewal 1 Reputation point
2022-05-24T20:30:14.377+00:00

I have to use a script task to connect to Teradata ADO.net connection which I have already created at project level.
In my script task , I need to connect to teradata to run some queries and do few modifications on the data i get.

Could someone guide me how i could connect to teradata within script task

Any help is appreciated.

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,083 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 43,926 Reputation points
    2022-05-26T07:51:31.333+00:00

    Hi Deepakgrewal-6294,

    Firstly, install the .NET Data Provider for Teradata.

    Step 1 Create a Console Project

    Name it as’' ‘ConsoleApps.Teradata’.

    Add reference to library ‘.NET Data Provider for Teradata'

    The version on my PC is 14.11.0.1. You can always download the latest version from Teradata official site.

    Step 2 Create a method to read data from Teradata
    Remember to import the namespace ‘Teradata.Client.Provider’.

    using System;
    using Teradata.Client.Provider;

    namespace ConsoleApps.Teradata
    {
    class Program
    {
    static void Main(string[] args)
    {
    DisplayEmployeeInfoFromTeraData();
    Console.ReadLine();

        }  
    
        private static void DisplayEmployeeInfoFromTeraData()  
        {  
        }  
    }  
    

    }

    Step 3 Implement the method
    Create connection, command and adapter objects to read data in a standard ADO.NET way.

    The sample code will be similar to what I’ve provided here:

    private static void DisplayEmployeeInfoFromTeraData()
    {
    var employeeData = new DataSet();

            var connectionString = "Data Source=***************;User ID=dbc;Password=dbc;";  
            using (var connection = new TdConnection(connectionString))  
            {  
                var sql = @"SELECT Emp.EmployeeID,  
    Emp.EmployeeName,  
      
    CASE  
        WHEN  Emp.Gendar = 'M' THEN 'Dear MR ' || Emp.EmployeeName ELSE 'Dear MS ' ||Emp.EmployeeName  
    END AS ""Employee Salutation""  
    FROM TD_MS_SAMPLE_DB.Employee Emp; ";  
                var command = new TdCommand(sql, connection);  
                var adapter = new TdDataAdapter(command);  
                connection.Open();  
                adapter.Fill(employeeData);  
                connection.Close();  
    
            }  
    
            DisplayEmployeeData(employeeData);  
        }  
    
        private static void DisplayEmployeeData(DataSet employeeData)  
        {  
            if (employeeData.Tables != null && employeeData.Tables.Count > 0)  
            {  
                var employees = employeeData.Tables[0];  
                var columnCount = employees.Columns.Count;  
                foreach (DataRow row in employees.Rows)  
                {  
                    for (int i = 0; i < columnCount; i++)  
                    {  
                        var col = employees.Columns[i];  
                        Console.WriteLine("{0} = {1}", col.ColumnName, row[i]);     
                    }  
                    Console.WriteLine();  
                }  
                Console.WriteLine("{0} Records", employees.Rows.Count);  
            }  
        }  
    

    In this sample, I am connecting to a local Teradata virtual machine with address as ‘192.168.121.128’. One thing to notice is that all the class names are prefixed with ‘Td’, e.g. Connection class is named TdConnection, Command class is named TdCommand and so forth.

    Step 4 The result will be displayed in the console.

    Summary

    Teradata is used in many data warehousing projects. If you really want to use it in your OLTP projects, you can connect to it via .NET Data Provider for Teradata or ODBC Teradata provider. The syntax will be similar as connecting to SQL Server, Oracle or any other databases supported by ADO.NET.

    I hope this answers your question.

    ---------------------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments