0

Update: It seems to be problem with ElephantSQL, the service I'm using according to this

However, I dont know where to add this.

Exact error:

FATAL: 28000: no pg_hba.conf entry for host "host", user "username", database "template1", SSL off

Similar error to this problem. Even after adding SslMode=require, I still couldn't connect to the database.

<add name="DefaultConnection" connectionString="Server=serverip;Port=5432;Database=dbname;User Id=username;Password=pass;CommandTimeout=60;Preload Reader=True;"/>

Weird thing is that it tried to connect to template1 instead of database specified in the connection string.

Connecting through pgadmin is fine though.

Community
  • 1
  • 1
Tuan Anh Tran
  • 6,807
  • 6
  • 37
  • 54
  • At a guess, PGADMIN connects through the superuser (postgres), which has a pg_hba.conf entry. You're connecting with a different user name, so you need a pga_hba.conf entry for that user name. pga_hba.conf is in your postgresql data directory - make a backup before you edit it! – mlinth Aug 19 '15 at 09:27
  • @mlinth pgadmin connects through the same user as i used in the connection string. I have no permission to edit the configuration on the database server though. – Tuan Anh Tran Aug 19 '15 at 09:32
  • _I still couldn't connect to the database_: please show the full error message. – Daniel Vérité Aug 19 '15 at 10:23
  • Please show the **full, exact error message** – Craig Ringer Aug 19 '15 at 11:31

2 Answers2

3

It's because you're on a shared ElphantSQL plan and can only connect to your own database. Npgsql tries to connect to template1 for some reason when it's checking server version, creating new databases etc, ignoring the database name given in the connection string. We'll submit a bug report to Npgsql.

Carl Hörberg
  • 5,973
  • 5
  • 41
  • 47
0

I am 4 years late to this party but had this issue with npgsql also and this question came up so hopefully this helps someone else in the same boat next time.

I was able to fix it by adding "EF Template Database=[MyDatabase]" to my connection string. The default for that value is "template1" according to npgsql documentation

JustinD
  • 1,646
  • 1
  • 12
  • 15