The Entity Framework provider type 'Npgsql.NpgsqlServices, EntityFramework6.Npgsql' registered in the application config file for the ADO.NET provider with invariant name 'Npgsql' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application

Just wasted way too much time for this:

The Entity Framework provider type 'Npgsql.NpgsqlServices, EntityFramework6.Npgsql' registered in the application config file for the ADO.NET provider with invariant name 'Npgsql' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

Obvious perhaps, but not so much anymore while being sure EntityFramework6.Npgsql has been installed... My project used to work a while ago and I could swear I had all the refs intact. After all it would not work otherwise, right...

Anyway, apart from making sure DbProviderFactories and providers are configured, just dbl check EntityFramework6.Npgsql is actually installed / output. If not reinstalling from nuget is a good start. Did work for me ;)

kill pg connection

PostgreSQL 9.2 and above:

SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB'
  AND pid <> pg_backend_pid();

PostgreSQL 9.1 and below:

SELECT pg_terminate_backend(pg_stat_activity.procpid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB'
  AND procpid <> pg_backend_pid();

Logging in pgsql

edit postgresql.conf and change the following:

log_statement = 'all'
log_min_duration_statement = 0
logging_collector = on
#log_directory = 'pg_log'

make sure pg_log is available relative to the data dir

restart pgsql service

Installing pgsql as a aservice on Windows

Get the latest pgsql from here and if you need postgis from here.

Unpack the pgsql zip to a desired destination.

Create a directory for the db files.

Navigate to the bin folder of pgsql and run the following command: 

initdb -U postgres -E UTF-8 -A md5 -D <path to data directory> -W

When prompted, provide the master pass. Your console should look like this:


Now it's time to adjust the db cfg. You may find it in the db files folder, it is called "postgresql.conf". Make sure you adjust the port the db listens on and also that it is available for localhost:

#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -

listen_addresses = 'localhost'		# what IP address(es) to listen on;
					# comma-separated list of addresses;
					# defaults to 'localhost'; use '*' for all
					# (change requires restart)
#port = 5432				# (change requires restart)

By default pgsql listens on 5432. If you already have another pgsql live or need to change it for whatever reason, simply adjust the port value.

Once this is ready, it's time to create a service for our db (you may need to run the console as an admin though):

pg_ctl register -N ServiceName -U postgres -P <password> -D <path to data directory> -w

The console should look like this:


And the service should be visible in the service manager:


If you wish to rename the service then simply delete it and register again:

sc delete ServiceName

The final step is to adjust the service properties, such as a user that runs the service (by default it runs as NetworkService) or the startup mode:



Now, if you also need postgis, simply use the exe installer and you're good to go.