dotConnect for PostgreSQL Documentation
In This Topic
    Network Tunneling
    In This Topic

    Usually when a client needs to connect to server it is assumed that a direct connection can be established. Nowadays though, due to security reasons or network topology, it is often necessary to use a proxy or bypass a firewall. This article describes different ways to connect to server with dotConnect for PostgreSQL.

    Direct connection

    Direct connection to server means that server host is accessible from client without extra routing and forwarding. This is the simplest case. The only network setting you need is Host parameter of connection string. This is also the fastest and most reliable way of communicating with server. Use it whenever possible.

    The following lines illustrate the simplicity:

    PgSqlConnection conn = new PgSqlConnection();
    conn.ConnectionString = "user id=postgres;password=postgres;host=localhost;";
    conn.Open();
    
    
    Dim conn As PgSqlConnection = New PgSqlConnection
    conn.ConnectionString = "user id=postgres;password=postgres;host=localhost;"
    conn.Open()
    
    

    Connection through proxy

    Sometimes it is necessary to connect to server in another network. For example, client address is 10.0.0.2, server address is 192.168.0.10. The client and server reside in different networks, so the client can reach it only through proxy at address 10.0.0.1, which listens on port 808. In this case in addition to connection string parameter Host you have to setup PgSqlConnection.ProxyOptions object as follows:

    PgSqlConnection conn = new PgSqlConnection();
    conn.ConnectionString = "user id=postgres;password=postgres;host=192.168.0.10;";
    conn.ProxyOptions.Host = "10.0.0.1";
    conn.ProxyOptions.Port = 808;
    conn.ProxyOptions.User = "ProxyUser";
    conn.ProxyOptions.Password = "ProxyPassword";
    conn.Open();
    
    
    Dim conn As PgSqlConnection = New PgSqlConnection
    conn.ConnectionString = "user id=postgres;password=postgres;host=localhost;"
    conn.ProxyOptions.Host = "10.0.0.1"
    conn.ProxyOptions.Port = 808
    conn.ProxyOptions.User = "ProxyUser"
    conn.ProxyOptions.Password = "ProxyPassword"
    conn.Open()
    
    

    Note that setting parameters of PgSqlConnection.ProxyOptions automatically enables use of proxy server. Connections through proxy are available when PgSqlConnection.Protocol property is Tcp (default) or Http.

    As usual, you can specify all settings in connection string:
    Port=3307;Proxy Host=10.0.0.1;Proxy Port=808;Proxy User=ProxyUser;Proxy Password=ProxyPassword;User ID=postgres;Password=postgres;Host=192.168.0.10;

    Additional information

    Keep in mind that traffic tunneling or encryption always increases CPU usage and network load. It is recommended that you use direct connection whenever possible.

    See Also

    PgSqlConnection Class  | Using Secure Connections