.netcore上的linux odbc连接到配置单元

agyaoht7  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(534)

我正在尝试从.netcore(v。1.0.1)linux上的应用程序(red hat 7.3 64位)。
program.cs代码:

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();
                }
            }
        }

我的项目设置文件: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>

运行“dotnet run”时,我收到以下错误:

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)

有人能帮忙修理吗?驱动程序(hortonworks odbc for hive)在此服务器上运行。这里的odbc连接库有问题。

mm9b1k5b

mm9b1k5b1#

看起来您正在尝试将其作为32位应用程序进行构建和加载,而hortonworks odbc for hive可能不支持这一点。需要检查一下hortonworks的文档。

相关问题