无法在 SQL 2019 Linux 上使用 PolyBase 通过 ODBC 查询 AS400

Unable to query AS400 over ODBC with PolyBase on SQL 2019 Linux

我想在查询 AS400 上的 DB2 数据库的 Ubuntu 容器中的 SQL Server 2019 实例 运行 上创建外部 table。我正在使用 ibm iaccess 1.1.0.15 amd64 ODBC 驱动程序。当我尝试创建外部 table 时,出现以下错误:

Msg 105082, Level 16, State 1, Line 15
105082;Generic ODBC error: NativeOdbcConnection.Open, error in OdbcConnectionCreate: SqlState: , NativeError: 111234, 'Error calling: SQLDriverConnect(this->_hdbc, NULL, (SQLWCHAR*)connectionString, SQL_NTS, NULL, 0, &cbConnStrOut, SQL_DRIVER_NOPROMPT), SQL return code: -1 | SQL Error Info: **Internal DmsNative error: SQLGetDiagRec returned: -1 | ConnectionPooling: 1 | Error calling: pConn->Create(connectionString, databaseName, useConnectionPooling, packetSize, connectionLoginTimeout, environmentSettings, transactionToken, transactionTokenSize, resourceGroupName, driverCapabilities, spid) | state: FFFF, number: 1, active connections: 1', Connection String: Driver={IBM i Access ODBC Driver};system=MYAS400SYSTEM;uid=MYAS400UID;server=MYAS400.MYDOMAIN.com.

这是我正在使用的 Dockerfile

# SQL Server Command Line Tools - custom image
# From Ubuntu 20.04 as base image
FROM ubuntu:20.04 as base

# Installing system utilities
RUN apt-get update && \
    apt-get install -y apt-transport-https curl gnupg && \
    # Adding custom MS repository
    curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
    curl https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list > /etc/apt/sources.list.d/mssql-server-2019.list && \
    curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | tee /etc/apt/sources.list.d/msprod.list
# From base image
FROM base as release

# Add the SQL startup scripts
COPY . /usr/src/app

COPY entrypoint.sh /
RUN chmod +x /entrypoint.sh

# Grant permissions for the setupsql script to be executable
RUN chmod +x /usr/src/app/setupsql.sh

# Installing SQL Server drivers and tools
RUN apt-get update 
RUN apt-get install -y mssql-server-polybase
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17
RUN ACCEPT_EULA=Y apt-get install -y mssql-tools 
# Install the IBM iAccess ODBC Driver
RUN dpkg -i /usr/src/app/ibm-iaccess-1.1.0.15-1.0.amd64.deb
RUN apt-get install -f
# Cleanup the Dockerfile
RUN apt-get clean && \
    rm -rf /var/lib/apt/lists

CMD exec /bin/bash entrypoint.sh

我可以使用 SSMS 通过本地主机连接到容器中的 SQL 服务器实例。创建凭据和数据源均成功。创建外部 table 是我收到错误的地方。

这里是 SQL 创建外部数据源和外部 table 的脚本:

CREATE DATABASE SCOPED CREDENTIAL AS400Credential
WITH IDENTITY = 'AS400UID',
SECRET = 'AS400PWD';  
GO

CREATE EXTERNAL DATA SOURCE MYAS400 WITH (LOCATION = 'odbc://MYAS400.MYDOMAIN.com', 
   CONNECTION_OPTIONS = 'DRIVER={IBM i Access ODBC Driver};SYSTEM=MYAS400;', 
   PUSHDOWN = OFF,
   CREDENTIAL = AS400CREDENTIAL);
GO

CREATE EXTERNAL TABLE EXT.Test 
(
    hstr NCHAR(50) NOT NULL,
    hreg NCHAR(50) NOT NULL,
    htr# NCHAR(50) NOT NULL,
    httm NCHAR(50) NOT NULL
)
WITH ( LOCATION='MYAS400DATABASE.SCHEMA.TABLE', DATA_SOURCE= MYAS400)

关于如何使用 PolyBase 成功连接到 AS400 有什么想法吗?

PolyBase 通用 ODBC 连接目前仅在 Windows 上可用。

This feature requires SQL Server on Windows.

Configure PolyBase to access external data with ODBC generic types

目前 Linked Server to non-SQL Server targets, and External Access and Unsafe CLR 也只有 Windows。

您可以使用 Python extensibility and pyodbc 来查询您的 iSeries。