Tuesday, August 2, 2016

connectivity to Netezza database using c#

Here is the working example of connectivity to Netezza database using c#
Steps 1  Install nzodbcsetup.exe on your development machine
Steps 2  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.OleDb;
using System.Data;
using System.Data.Odbc;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            GetDataFromNetezzaTable();
           
            
       }
        static void GetDataFromNetezzaTable()
        {
           

            OdbcConnection conn = new OdbcConnection();
            conn.ConnectionString = "Driver={NetezzaSQL};servername=servername;port=5480;database=databasename; username=username;password=password;";

            OdbcDataReader dr = null;

            try
            {
                conn.Open();
                System.Data.Odbc.OdbcCommand cmd = new System.Data.Odbc.OdbcCommand("SELECT * FROM Table", conn);
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    Console.WriteLine(dr[0]);
                    
                }
                Console.ReadLine();
            }
            finally
            {
                // close the reader
                if (dr != null)
                {
                    dr.Close();
                }

                // close the connection
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
            
    }
}


Cheers
Shukraj khadse
SharePoint & .Net Solution Architect
L&T Infotech Limited
New York,USA