3

Can you please advise whether there's a way how to connect to Postgres SQL DB from PowerShell WITHOUT installing any DB driver? I'm looking for solution which would be able to connect using only .NET database capabilities. Thanks.

Matthew

Martinecko
  • 1,719
  • 4
  • 22
  • 35

1 Answers1

8

With no client driver at all, you can simply execute the psql command-line then read and process its output. This is particularly useful when invoking it as psql -qAt and/or using \copy.

Otherwise you must have some kind of client driver. Powershell has no built-in support code for the PostgreSQL protocol, so it therefore cannot communicate with PostgreSQL without some kind of client driver. nPgSQL would be the most obvious choice since it integrates well in .NET and is composed only of .NET assemblies. You could probably bundle nPgSQL up as a Powershell extension... but as usual, someone already did that.

Otherwise you probably want to install psqlODBC, which is a simple msiexec to install then usable using the usual ODBC support.

(The only reason Powershell can talk to MS SQL without installing additional drivers is that drivers for MS SQL are built in).

Community
  • 1
  • 1
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • What I'm trying to achieve is simply to verify user/password to access database. All I need to know is whether user is able to connect to DB. But I need to do this automatically via PowerShell. Any ideas? – Martinecko May 27 '15 at 13:03
  • 1
    I think I would recommend Npgsql over ODBC. – Ben Collins Mar 31 '16 at 17:46