title: System.Net.Sockets.SocketException on postgres connection
body: <p>I have this app where I connect to a Postgres DB. I have my Connection function, but every time I try to connect to the DB i get the exception:</p>
  
  <blockquote>
    <p>{System.Net.Sockets.SocketException (0x80004005): Connection refused  at Npgsql.NpgsqlConnector.Connect (Npgsql.NpgsqlTimeout timeout) [0x001f5] in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:733   at Npgsql.NpgsqlConnector+d__153.MoveNext () [0x005a0] in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:648 --- End of stack trace from previous location where exception was thrown ---  at Npgsql.NpgsqlConnector+d__149.MoveNext () [0x003e1] in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:455 --- End of stack trace from previous location where exception was thrown ---  at Npgsql.ConnectorPool+d__19.MoveNext () [0x001cf] in C:\projects\npgsql\src\Npgsql\ConnectorPool.cs:300 --- End of stack trace from previous location where exception was thrown ---  at System.Threading.Tasks.ValueTask<code>1[TResult].get_Result () [0x00022] in &lt;1d288dd8ebaf4c6f890e1e99a5a184f0&gt;:0   at System.Runtime.CompilerServices.ValueTaskAwaiter</code>1[TResult].GetResult () [0x00000] in &lt;1d288dd8ebaf4c6f890e1e99a5a184f0>:0   at Npgsql.NpgsqlConnection+&lt;>c__DisplayClass32_0+&lt;g__OpenLong|0>d.MoveNext () [0x0046d] in C:\projects\npgsql\src\Npgsql\NpgsqlConnection.cs:331 --- End of stack trace from previous location where exception was thrown ---  at Npgsql.NpgsqlConnection.Open () [0x00000] in C:\projects\npgsql\src\Npgsql\NpgsqlConnection.cs:153   at App1.MainPage.conexao () [0x00054] in C:\Users\Mario\Documents\projetos\App1\App1\App1\MainPage.xaml.cs:40 }</p>
  </blockquote>
  
  <p>here is the code I'm trying to use:</p>
  
  <pre><code>   private void conexao()
      {
          NpgsqlConnection pgsqlConnection = null;
          var connString = string.Format("Server={0};Port={1};User Id={2};Password={3};Database={4};",
                                               serverName, port, userName, password, databaseName);
          DataTable dt = new DataTable();
  
          try
          {
              using (pgsqlConnection = new NpgsqlConnection(connString))
              {
                  usuario usuario = new usuario();
                  // abre a conexão com o PgSQL e define a instrução SQL
                  pgsqlConnection.Open();
                  string cmdSeleciona = "Select * from funcionarios order by id_funcionario";
                  List&lt;string&gt; lista = new List&lt;string&gt;();
                  NpgsqlCommand cmd = new NpgsqlCommand(cmdSeleciona, pgsqlConnection);
                  var reader = cmd.ExecuteReader();
                  while (reader.Read())
                  {
                      usuario.nome_funcionario = reader["nome_funcionario"].ToString();
                      usuario.email = reader["email"].ToString();
                  }
                  //using (NpgsqlDataAdapter Adpt = new NpgsqlDataAdapter(cmdSeleciona, pgsqlConnection))
                  //{
                  //}
              }
          }
          catch (NpgsqlException ex)
          {
              throw ex;
          }
          catch (Exception ex)
          {
              throw ex;
          }
          finally
          {
              pgsqlConnection.Close();
          }
      }
  </code></pre>
  
  <p>The exception occurs on:<code>pgsqlConnection.Open();</code></p>