我使用freetds在postgresql中设置了外部数据包装程序以连接到SQL Server,并在postgresql中安装了tds_fdw
扩展名,但是当从外部表中选择数据时,代码总是会引发此DB-Library错误:< / p>
数据库#:4075错误:
USE数据库语句失败,因为较旧的客户端驱动程序无法识别数据库排序规则Persian_100_CI_AI。尝试升级客户端操作系统或将服务更新应用于数据库客户端软件,或使用其他排序规则。有关更改排序规则的更多信息,请参见SQL Server联机丛书
我深入研究了/etc/freetds
上的net和config 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\''
这样的反斜杠转义字符不起作用,并给出语法错误。
任何帮助将不胜感激。
答案 0 :(得分:0)
根据this github issue,您需要使用至少tds_version
中的7.3
才能成功连接。尝试在您的CREATE SERVER
语句中进行更改。
答案 1 :(得分:0)
根据此问题https://github.com/tds-fdw/tds_fdw/issues/56 我认为用户'bpms'没有您的表的授予权限。