I have to connect with database remotely, i.e. I use my computer and I connect with some computer (using Remote Desktop Connection). Then I try to connect with psql database, which is on another server. I can connect with it through Terminal (it works), but I have to use it in my C# script. I've read that I should use Npgsql.dll (I downloaded Npgsql-2.2.3-net35). In order to connect to the database I wrote:
string connstring = "Host=xxx.xx.xxx.xxx;Port=5432;Database=yy;"
+ "User=zz;Password=xxxxxx;CommandTimeout=20;Ssl=true;";
NpgsqlConnection conn = new NpgsqlConnection (connstring);
if (conn != null && conn.State == ConnectionState.Closed)
{
Console.WriteLine ("Connection closed");
}
else
{
Console.WriteLine ("Connection opened");
};
conn.Open();
if (conn != null && conn.State == ConnectionState.Closed)
{
Console.WriteLine ("Connection closed");
}
else
{
Console.WriteLine ("Connection opened");
};
When I try to run my script, it doesn't work. I don't get any error but nothing after conn.Open() is return. I think, that it could be a question of connection string, because when I remove Ssl=true, I receive FATAL: 28000: no pg_hba.conf for host (here is IP of my remote computer), user "zz", database "yy", SSL off.
Is here anyone who could help my to resolve my problem?