PowerShell 连接到 Postgres 数据库

PowerShell connect to Postgres DB

能否请您告知是否有一种方法可以在不安装任何数据库驱动程序的情况下从 PowerShell 连接到 Postgres SQL 数据库?我正在寻找能够仅使用 .NET 数据库功能进行连接的解决方案。谢谢。

马修

根本没有客户端驱动程序,您可以简单地执行 psql 命令行,然后读取并处理其输出。这在使用 \copy.

作为 psql -qAt and/or 调用时特别有用

否则你必须有某种客户端驱动程序。 Powershell 没有对 PostgreSQL 协议的内置支持代码,因此它 不能 在没有某种客户端驱动程序的情况下与 PostgreSQL 通信。 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.

否则你可能想要安装 psqlODBC,这是一个简单的 msiexec 安装然后 usable using the usual ODBC support

(Powershell 可以在不安装额外驱动程序的情况下与 MS SQL 通信的唯一原因是内置了用于 MS SQL 的驱动程序)。