0
我有几个SQL脚本可以使用PowerShell针对PostgreSQL实例运行。 我已经安装了PSQL 9.5以及ODBC驱动程序。我也将它添加到DSN列表无法打开与PostgreSQL的连接
名称:PostgreSQL35W
驱动程序:在PostgreSQL的Unicode(64)
在PowerShell中我有一个代码块
$DBConnectionString = "Driver={PostgreSQL Unicode(x64)};Server=$dbServer;Port=5432;Uid=$dbUser;Pwd=$dbPass;"
$DBConn = New-Object System.Data.Odbc.OdbcConnection;
$DBConn.ConnectionString = $DBConnectionString;
$DBConn.Open();
$DBCmd = $DBConn.CreateCommand();
$DBCmd.CommandText = $script;
$DBCmd.ExecuteReader();
$DBConn.Close();
当试图连接到PSQL例如,我收到一个没有说明的例外:
Exception calling "Open" with "0" argument(s): "" At C:\Projects\Scripts\Publish\PublishDB.ps1:34 char:5 + $DBConn.Open(); + ~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : OdbcException
试图找到任何有关相关问题 - 没有运气。
如果你定义你应该使用[DSN连接字符串(https://www.connectionstrings.com/odbc-dsn/),否则将DSN将DSN毫无意义。如果您想使用“常规”[PostgreSQL ODBC连接字符串](https://www.connectionstrings.com/postgresql-odbc-driver-psqlodbc/):您是否定义了您在其中使用的变量?另外,你似乎没有指定数据库。你是否尝试'PostgreSQL UNICODE'而不是'PostgreSQL Unicode(x64)'作为驱动程序? –
我做了,它说这样的驱动程序没有安装。 – Refraction