PowerShell connect to Postgres DB

匿名 (未验证) 提交于 2019-12-03 09:58:14

问题:

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:

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



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!