【问题标题】:Postgresql foreign data wrapper raises error when retrieving any foreign table data from SQL Server从 SQL Server 检索任何外部表数据时,Postgresql 外部数据包装器引发错误
【发布时间】:2019-04-06 19:59:38
【问题描述】:

我在 postgresql 中设置了外部数据包装器,使用 freetds 连接到 SQL Server,并在 postgresql 中安装了tds_fdw 扩展,但是当从外部表中选择数据时,代码总是引发此 DB-Library 错误:

数据库编号:4075 错误:
USE 数据库语句失败,因为旧客户端驱动程序无法识别数据库排序规则 Persian_100_CI_AI。尝试升级客户端操作系统或对数据库客户端软件应用服务更新,或使用不同的排序规则。有关更改排序规则的详细信息,请参阅 SQL Server 联机丛书

我深入研究 net 并配置位于 /etc/freetds 的 freets.conf 文件

[global]
        # TDS protocol version
;       tds version = 8.0

        # Whether to write a TDSDUMP file for diagnostic purposes
        # (setting this to /tmp is insecure on a multi-user system)
;       dump file = /tmp/freetds.log
;       debug flags = 0xffff

        # Command and connection timeouts
;       timeout = 10
;       connect timeout = 10

        # If you get out-of-memory errors, it may mean that your client
        # is trying to allocate a huge buffer for a TEXT field.
        # Try setting 'text size' to a more reasonable limit
        text size = 64512
        client charset = UTF-8
# A typical Sybase server
[egServer50]
        host = symachine.domain.com
        port = 5000
        tds version = 5.0

# A typical Microsoft server
[mssql]
        host = 192.168.x.x
        port = 1433
        tds version = 7.1

这是我在 postgres 中的 sql 代码

CREATE SERVER prs_server
FOREIGN DATA WRAPPER tds_fdw
OPTIONS (servername '192.168.x.x', port '1433',database 'prs_bpms', tds_version '7.1', msg_handler 'notice');

CREATE USER MAPPING FOR postgres
SERVER prs_server
OPTIONS (username 'bpms', password 'xxxx');

CREATE FOREIGN TABLE prs_table (
    FirstName varchar null,
       LastName varchar nuul,
       SSN varchar not null

)
SERVER prs_server 
OPTIONS (query 'SELECT top 10 [FirstName],[LastName],[SSN] FROM [dbo].[prs_Personnel] ');


SELECT * FROM prs_table;

而且我还需要使用 where 子句,但是像 'select from where ssn = \'1234\'' 这样的反斜杠转义字符不起作用并给出语法错误。

任何帮助将不胜感激..

【问题讨论】:

    标签: sql sql-server postgresql freetds foreign-data-wrapper


    【解决方案1】:

    根据this github issue,你需要使用至少7.3中的tds_version才能连接成功。尝试在您的 CREATE SERVER 语句中更改它。

    【讨论】:

      【解决方案2】:

      根据这个问题https://github.com/tds-fdw/tds_fdw/issues/56 我认为用户 'bpm' 没有授予您的表的权限。

      【讨论】:

        猜你喜欢
        • 2018-08-30
        • 1970-01-01
        • 2020-05-12
        • 1970-01-01
        • 2019-01-14
        • 2021-06-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多