2

I can't find documentation about it. The SQL type provider I'm using is this one.

This is my code so far trying to use Renci.SshNet

open FSharp.Data.Sql
open Renci.SshNet
open System

let connectionInfo = new Renci.SshNet.PasswordConnectionInfo("159.203.79.134", "root", "322M5m@Q9Exs")
connectionInfo.Timeout <- TimeSpan.FromSeconds(30.0)
let client = new SshClient(connectionInfo)
client.Connect();
let portFw = new ForwardedPortRemote(Convert.ToUInt32(22),"159.203.79.134",Convert.ToUInt32(5432))
client.AddForwardedPort(portFwld)
portFwld.Start()

let [<Literal>] connString = "Host=***;Port=22;Database=testdb;Username=postgres;Password=***;"
let [<Literal>] dbVendor = Common.DatabaseProviderTypes.POSTGRESQL
let [<Literal>] resPath = @"../packages/Npgsql.3.1.9/lib/net451/"
let [<Literal>] indivAmount = 1000
let [<Literal>] useOptTypes = true

type sql = SqlDataProvider<dbVendor,connString,"",resPath,indivAmount,useOptTypes>

[<EntryPoint>]
let main argv =
    let ctx = sql.GetDataContext()
    printfn "%A" argv
    0

But this only hangs.

This is how I connect to it through PG Commander connection

s952163
  • 6,276
  • 4
  • 23
  • 47
Lay González
  • 2,901
  • 21
  • 41
  • 1
    Have you tried anything? – Fyodor Soikin Dec 05 '16 at 04:12
  • @FyodorSoikin I've tried everything from here https://www.connectionstrings.com/postgresql/ It seems that it has to do nothing with the connection string but that I need to create first a ssh client. I'm trying with Renci.SshNet but I don't know which would be the host and which the bound host... I'm lost. It's my first time doing this. I'm trying to implement this comment: http://stackoverflow.com/a/33857223/1120410 – Lay González Dec 05 '16 at 04:22
  • 1
    Please describe everything you tried, along with results you got, in the question. Provide code samples, error messages. Without detailed information about your problem nobody can help you to solve it. – Fyodor Soikin Dec 05 '16 at 04:32
  • @FyodorSoikin Thanks for your feedback! I edited my question with it in mind. – Lay González Dec 05 '16 at 04:44
  • @FyodorSoikin I further improved my question – Lay González Dec 05 '16 at 04:50
  • if you take out the type provider, and just try to connect to your postgres database, via `psql`, does that work? Something like: `psql -h localhost -p portNum -U your-db-username database-name`. See: [SSH tunnel](https://www.postgresql.org/docs/current/static/ssh-tunnels.html). – s952163 Dec 05 '16 at 04:51
  • @s952163 No, it returns psql: FATAL: no pg_hba.conf entry for host "187.190.152.199", user "postgres", database "pruebaf", SSL on FATAL: no pg_hba.conf entry for host "187.190.152.199", user "postgres", database "pruebaf", SSL off And your suggestion is ignoring the fact that I need to connect through a ssh tunnel – Lay González Dec 05 '16 at 04:55
  • I mean set up the SSH tunnel first, hence the link, then psql to it via the localhost. I think before you can use the type provider it's probably better to trouble-shoot your SSH to postgres connection first. If you can connect via psql, then check if you can connect with npgsql using ADO.NET over ssh, if that works, then try the type provider. – s952163 Dec 05 '16 at 05:10
  • 1
    @s952163 My bad. Yes, I'm able to connect that way. First I establish the tunnel on my machine: ssh -L 63333:localhost:22 root@159.203.**.** Then I connect to the db: psql -h 159.203.**.** -p 5432 -U postgres pruebaf How would that look using Renci.SshNet? Which is the bound port and which is the port? Right now, Renci.SshNet is crapping, so I can't just try everything. What I've tried is what it is on the post. Is it a ForwardedPortLocal or a ForwardedPortLocal? Thanks a lot! – Lay González Dec 05 '16 at 06:21
  • I'm not familiar with Renci.SshNet, my guess is that it would be actually `ForwardedPortLocal` as you say, also I wonder if you can actually forward 5432 as that's already being used by postgres, use some higher portnumber exactly as in your tunneling example. – s952163 Dec 05 '16 at 06:32

0 Answers0