My database is postgresql, which is placed on a Linux server.
Now I want to communicate with it through the C# program that is on the Windows operating system.
to connect to this database, there is a public encrypted file on the server and I have to send my private file to establish the connection.
That is, communication is done through a .ppk file and through SSH.
This is a simple connection string without ssh and sending a private file :
public static NpgsqlConnection connOldSamin = new NpgsqlConnection("Host=192.168.0.16;Port=5432;Database=sale;Username=postgres;Password=123;SSL Mode=Require;Trust Server Certificate=true");
But I don’t know how to send my ppk file along with this string !!
2
Answers
You will need to use a library that can handle SSH connections. Multiple available one of which is Renci.SshNet. Install the Nuget package and then you can use it to create an SSH client, connect to the Linux server using the .ppk file and your connection string, and then use that SSH client to create a tunnel to the PostgreSQL server.
you can use a library such as SSH.NET
and