I'm trying to connect to Hive from .netcore (v. 1.0.1) app on linux (Red Hat 7.3 64-bit).
Program.cs code:
using System;
using System.Data.Odbc;
using System.Collections;
using System.Collections.Generic;
namespace app
{
class Program
{
static void Main(string[] args)
{
var connectionString = "DSN=Hadoop Hive";
var createTableCommandText = "CREATE TABLE Searches(searchTerm STRING, userid BIGINT,userIp STRING) " +
"COMMENT 'Stores all searches for data' " +
"PARTITIONED BY(searchTime DATE) " +
"STORED AS SEQUENCEFILE;";
using (var connection = new OdbcConnection(connectionString))
{
using (var command = new OdbcCommand(createTableCommandText, connection))
{
try
{
connection.Open();
// Create a table.
command.ExecuteNonQuery();
// Insert row of data.
command.CommandText = "INSERT INTO TABLE Searches PARTITION (searchTime = '2015-02-08') " +
"VALUES ('search term', 1, '127.0.0.1')";
command.ExecuteNonQuery();
// Reading data from Hadoop.
command.CommandText = "SELECT * FROM Searches";
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
for (var i = 0; i < reader.FieldCount; i++)
{
Console.WriteLine(reader[i]);
}
}
}
}
catch (OdbcException ex)
{
Console.WriteLine(ex.Message);
throw;
}
finally
{
Drop table
command.CommandText = "DROP TABLE Searches";
command.ExecuteNonQuery();
}
}
}
My project settings file: app.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<PackageId>HadoopLibrary</PackageId>
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Data.Common" Version="4.3.0" />
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
<PackageReference Include="System.Collections.NonGeneric" Version="4.0.1" />
<PackageReference Include="MSA.NetCore.ODBC" Version="1.0.3" />
</ItemGroup>
When running "dotnet run" I receive the following error:
Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'odbc32.dll': The specified module could not be found.
(Exception from HRESULT: 0x8007007E)
at System.Data.Odbc.libodbc.SQLAllocHandle(OdbcHandleType HandleType, IntPtr InputHandle, IntPtr& OutputHandlePtr)
at System.Data.Odbc.OdbcConnection.Open()
at hwapp.Program.Main(String[] args)
Can anyone help how to fix that? The driver (Hortonworks ODBC for Hive) works on this server. There is an issue with the library for ODBC connection here.
it looks like you are trying to build and load it as a 32-bit application and that's what Hortonworks ODBC for Hive may not support. Need to check the documentation of Hortonworks for that.
User contributions licensed under CC BY-SA 3.0