In this tutorial, we will walk through how to connect to any database from .NET Core using Progress DataDirect’s ODBC Connectors on Windows. This tutorial uses Progress DataDirect’s ODBC Driver for Apache Hadoop Hive to demonstrate how to connect to it from .NET Core, but the same steps can be applied to any of our ODBC Connectors.
Install-Package System.Data.Odbc -Version 4.7.0dotnet add package System.Data.Odbc --version 4.7.0using System;using System.Data.Odbc;namespace DataDirectODBCConnect{    class Program    {        static void Main(string[] args)        {            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder            {                Driver = "DataDirect 8.0 Apache Hive Wire Protocol"            };            builder.Add("HostName", "192.168.1.1");            builder.Add("PortNumber", "10000");            builder.Add("Database", "mydb");            builder.Add("UID", "username");            builder.Add("PWD", "password");            using (OdbcConnection connection = new OdbcConnection(builder.ConnectionString))            {                string sqlQuery = "SELECT activityid, emailaddress, activitydate FROM emails limit 100";                OdbcCommand command = new OdbcCommand(sqlQuery, connection);                connection.Open();                OdbcDataReader reader = command.ExecuteReader();                //Print Column Names                for (int i=0; i< reader.FieldCount; i++)                {                    Console.Write(reader.GetName(i) + "\t");                }                Console.Write("\n");                if(reader.HasRows)                {                    while(reader.Read())                    {                        Console.WriteLine("{0}\t{1}\t{2}", reader.GetInt32(0), reader.GetString(1), reader.GetString(2));                    }                }                reader.Close();                command.Dispose();            }        }    }}
We hope this tutorial helped you to connect to Hive from .NET Core using Progress DataDirect’s ODBC Driver for Apache Hadoop Hive. Feel free to download any Progress DataDirect ODBC connector and try it out. Please contact us with any questions and we will be happy to help.