npgsql - stop using 'template1' database

entity-framework entity-framework-6 npgsql


I want to use elephantsql database with entity framework (whichever version). I found tutorial on the internet about npgsql which can help me connect those 2 piece of technology.

I made an object which will represent object from DB :

[Table("typychorob", Schema = "public")]
public class TypChoroby
    public TypChoroby()

    [Key, Column("id"), DatabaseGenerated(DatabaseGeneratedOption.Identity), Required]
    public int ID { get; set; }

    [Column("nazwa"), MaxLength(50)]
    public string Nazwa { get; set; }

I created class which will represent dBContext. Uzytkownik is nearly the same as TypChoroby.

public class PrzychodniaContext : DbContext
    public DbSet<Uzytkownik> Uzytkownicy { get; set; }
    public DbSet<TypChoroby> TypyChorob { get; set; }

    public PrzychodniaContext() : base()

I try to use those things in the following style :

using (var context = new PrzychodniaContext())
            context.Database.Log = post;
            var chorobska = context.TypyChorob.ToList();

This always creates error like this :

{"28000: no pg_hba.conf entry for host \"\", user \"jnwnqqog\", database \"template1\", SSL off"}

It's elephantSql simplest plan so i cannot edit pg_hba.conf which is a file where i can give myself some privileges.

My ConnectionString :

<add name="PrzychodniaContext" connectionString="Server=YouDontWantToKnowButYouKnow;Database=jnwnqqog;User Id=jnwnqqog;Password=YouDontWantToKnow;MAXPOOLSIZE=5;" providerName="Npgsql" />

What i tried?

1) First i know what's going on. In documentation of npgsql in create database command i found :

The name of the template from which to create the new database, or DEFAULT to use the default template (template1).

Honetsly i do not know how to change that. I though that it would be good to change that to 'jnwnqqog', because it's my DB at elephantSQL. But i do not know.

2) I'd used Database.SetInitializer(null); I assumed that it will stop trying to create new database. It did not stopped this behaviour.

3) I tried to enable/disable SSL.

4) I changed entity framework from 5.0 to 6.0 along with npgsql.

For all curious : -why elephantsql and postgresql with visual studio? - university project. Honestly i would like to use mssql but i cannot. Only progresql.

Edit : I tried to read many questions/tutorials/bug tracker stories/etc. Did not find my answer. Edit2 : Sorry i forgot. ElephantSQL is an postgresql database hosted in cloud.

1/5/2017 10:44:51 PM

Accepted Answer

I made it :).

If someone ever will have same problem as me then you need to add this to your connection string:


Then it will stop using 'template1'.

1/6/2017 6:28:58 AM

Popular Answer

Updating npgsql dll and adding EntityAdminDatabase=[DATABASE_NAME] in connection string Works for me.


Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow