In this tutorial, we will walk through how you to connect to any database from .NET Core using Progress DataDirect ODBC Connectors on Linux. This tutorial uses the Progress DataDirect’s ODBC Driver for Apache Hadoop Hive to demonstrate how we can connect to it from .NET Core, but the same steps can be applied to any of our ODBC Connectors.
tar -xvf PROGRESS_DATADIRECT_ODBC_HIVE_LINUX_64.tgz
./PROGRESS_DATADIRECT_ODBC_8.0_LINUX_64_INSTALL.bin
[progress@centos7264 ODBC_80_64bit]$ echo $LD_LIBRARY_PATH && echo $ODBCINI && echo $ODBCINST
/home/progress/Progress/DataDirect/ODBC_80_64bit/lib:/home/progress/Progress/DataDirect/ODBC_80_64bit/jre/lib/amd64/server
/home/progress/Progress/DataDirect/ODBC_80_64bit/odbc.ini
/home/progress/Progress/DataDirect/ODBC_80_64bit/odbcinst.ini
sudo yum install unixODBC-devel unixODBC
sudo apt-get install unixODBC-dev unixODBC
dotnet add package System.Data.Odbc --version 4.7.0
using
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();
}
}
}
}
dotnet <
yourproject
>.dll
We hope this tutorial explained how to connect to any database 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.