title: Npgsql connection string for local Postgres
body: <p>Good afternoon.</p>
  
  <p>I'm having troubles getting connected to a Postgres database.</p>
  
  <p>The app I'm working on has to run on .NET 4. I'm using Npgsql, and because I'm limited to .NET 4, I'm using Npgsql version 2.2.7 (I believe 3+ requires .NET 4.5).</p>
  
  <p>The application will be running on the same machine as Postgres is. The database is installed and set up by a third party, and for that reason I'm unable to change the pg_hba.conf file.</p>
  
  <p>My first stab at a connection string looked like this:</p>
  
  <pre><code>Server=localhost;Database=xyz;Integrated Security=true;
  </code></pre>
  
  <p>But I got this error:</p>
  
  <pre><code>FATAL: 28000: no pg_hba.conf entry for host "::1", user "SYSTEM", database "xyz", SSL off
  </code></pre>
  
  <p>Researched that error, and tried numerous other variations of the connection string to fix this, including:</p>
  
  <pre><code>Server=127.0.0.1;Database=xyz;Integrated Security=true;
  Server=-h 127.0.0.1;Database=xyz;Integrated Security=true;
  Server=127.0.0.1/32;Database=xyz;Integrated Security=true;
  Server=::1;Database=xyz;Integrated Security=true;
  Server=::1/128;Database=xyz;Integrated Security=true;
  </code></pre>
  
  <p>But nothing works. I either get the</p>
  
  <pre><code>FATAL: 28000 ...
  </code></pre>
  
  <p>error, or a simple</p>
  
  <pre><code>Failed to establish a connection to ...
  </code></pre>
  
  <p>The pg_hba.conf file looks like this:</p>
  
  <pre><code>host all postgres 127.0.0.1/32  trust
  host all xyz      127.0.0.1/32  trust
  host all xyz      ::1/128       trust
  host all postgres ::1/128       trust
  </code></pre>
  
  <p>This is all running on a Windows 7 machine, and IPv6 is turned off on the network connection.</p>
  
  <p>It's probably something simple, but what can I do? I can't change the pg_hba.conf file, so how can I tweak my connection string to work?</p>