4

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

1 Answer 1

9

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).

Sign up to request clarification or add additional context in comments.

2 Comments

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?
I think I would recommend Npgsql over ODBC.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.