I set up foreign data wrapper in postgresql using freetds to connect to SQL Server and installed the tds_fdw
extension in postgresql, but when selecting data from a foreign table, the code always raises this DB-Library error:
DB #: 4075 error:
The USE database statement failed because the database collation Persian_100_CI_AI is not recognized by older client drivers. Try upgrading the client operating system or applying a service update to the database client software, or use a different collation. See SQL Server Books Online for more information on changing collations
I delve into net and config freets.conf file located in /etc/freetds
[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
here is my sql code in postgres
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;
And also I need to use where clause but backslash escape character like 'select from where ssn = \\'1234\\''
doesn't work and gives syntax error.
Any help would be appreciated..
According to this github issue , you need to use tds_version
of at least 7.3
to connect successfully. Try changing it in your CREATE SERVER
statement.
根据这个问题https://github.com/tds-fdw/tds_fdw/issues/56我认为用户 'bpms' 没有授予你的表的权限。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.