title: SQL Server 2012: Add a linked server to PostgreSQL
body: <p>I try to connect a PostgreSQL to SQL Server 2012 server as linked server</p>
  
  <p>I found some advices on different forum and follow it. But I'm stuck with an authentication problem.</p>
  
  <p>I explain:</p>
  
  <p>On the SQL Server, I have install the ODBC driver for PostgreSQL (psqlodbc_09_02_0100-x64). I created a system DSN to a specific database on the PostgreSQL. This DSN work correctly.</p>
  
  <p>Using SSMS, I run this command to add the linked server:</p>
  
  <pre><code>EXEC master.dbo.sp_addlinkedserver 
  @server = N'lnk_test', 
  @srvproduct=N'PostgreSQL Unicode(x64)', 
  @provider=N'MSDASQL', 
  @provstr=N'Driver=PostgreSQL Unicode(x64);uid=postgres;Server=test1;database=accueil;pwd=MyPassword;SSLmode=disable;PORT=5432'
  
  EXEC master.dbo.sp_addlinkedsrvlogin 
  @rmtsrvname=N'lnk_test',
  @useself=N'True',
  @locallogin=NULL,
  @rmtuser=NULL,
  @rmtpassword=NULL
  </code></pre>
  
  <p>After running, I have a new Linked Server called "lnk_test". When I receive the following error message:</p>
  
  <pre><code>Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "pgTest1_accueil".
  OLE DB provider "MSDASQL" for linked server "pgTest1_accueil" returned message "[Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed".
  OLE DB provider "MSDASQL" for linked server "pgTest1_accueil" returned message "FATAL: authentification par mot de passe échouée pour l'utilisateur  « postgres »". (Microsoft SQL Server, Error: 7303)
  </code></pre>
  
  <p>The error message is in french, the traduction is: "authentication by password failed for user "postgres". I find the same error message in the log of the PostgreSQL server.</p>
  
  <p>Is someone have an idea for resolving this problem?</p>
  
  <p>Thanks in advance.</p>
  
  <p>Jerome</p>
  
  <p><strong>[Update 2/08/2013]</strong>
  I complete this post with the result of a test I realize today.</p>
  
  <p>WHen using a packet sniffer, I check the packets sended when testing the connection through the ODBS Data Source Administrator (64-bit) and through the Linked Server under SSMS.</p>
  
  <p>The data are the same between the 2 system for:</p>
  
  <ul>
  <li><p>Opening the connection to the PostgreSQL</p></li>
  <li><p>Sending the connection string (all parameters are the same)</p></li>
  <li><p>the response of PostgreSQL asking for password (only different is the salt value, but it's normal)</p></li>
  <li><p>the password are sended in the same way (crypted with MD5)</p></li>
  </ul>
  
  <p>But after, the response of the server differ:</p>
  
  <p>For the ODBC Data Source, all works correctly. I receive the authentication and can send test query. </p>
  
  <p>For SSMS, I receive an error message (as describe upper).</p>