将PostgreSQL 9.5(odbc)作为链接服务器连接到SQL Server 2012时出错

时间:2016-02-04 07:07:00

标签: sql-server postgresql odbc

我在SQL Server 2012上将PostgreSQL数据库连接为链接服务器时收到错误。

首先,我尝试了MS Access的本地连接,但工作正常。所以我试着在我的SQL Server 2012上做同样的事情。

我从PostgreSQL ODBC Driver Repo设置了ODBCx64驱动程序,连接测试成功http://imgur.com/6dXiwia

但如果我想在SQL Server Mgmt Studio中将其添加为链接服务器,则无法连接http://imgur.com/13wihSh

为什么它无法连接而没有错误的任何提示?

我正在使用:

  • PostgreSQL 9.5
  • SQL Server 2012
  • Windows Server 2012
  • Postgres的ODBC_X64_Unicode

1 个答案:

答案 0 :(得分:1)

我找到了一个适合我的解决方案。

Microsoft SQL Server Management Studio中的向导没有帮助,我自己设置了连接。我已经用选择对它进行了测试,它可以正常工作

这是我使用的代码:

EXEC master.dbo.sp_addlinkedserver 
@server = N'NameShownInMSSQLSrvMgmtStudio', 
@srvproduct=N'PostgreSQL Unicode(x64)', 
@provider=N'MSDASQL', 
@provstr=N'Driver=PostgreSQL Unicode(x64);uid=postgres;Server=SERVERNAME;database=DBNAME;pwd=MyPWD;SSLmode=disable;PORT=5432'

EXEC master.dbo.sp_addlinkedsrvlogin 
@rmtsrvname=N'postgresql',
@useself=N'True',
@locallogin=NULL,
@rmtuser=YourUser,
@rmtpassword=YourPW