3
OdbcConnectionを使用してPostgreSQLサーバに接続できました。Postgresqlデータベースに接続してSQLコマンドを実行するとInvoke-Sqlcmdが失敗する
$DBConnectionString = "Driver={PostgreSQL ANSI(x64)};Server=$MyServer;Port=$MyPort;Database=$MyDB;Uid=$MyUid;Pwd=$MyPass;"
$DBConn = New-Object System.Data.Odbc.OdbcConnection;
$DBConn.ConnectionString = $DBConnectionString;
$DBConn.Open();
しかし、Invoke-Sqkcmdコマンドを使用してPostgreSQLに接続したいとします。私は、常にコマンドレットとそのコマンドを使用しようとしました。私はそれを試しました:
$MyPort = '5432'
$MyUid = 'postgres'
$MyPass = 'pass'
$DBSvr = 'server'
$DBase = 'database'
$sqlcmd = 'SELECT email_addr FROM member_subscribers LIMIT 20'
$data = Invoke-Sqlcmd -query $sqlcmd -Database $DBase -ServerInstance $DBSvr$MyPort -Username $MyUid -Password $MyPass
Write-Output $data
しかし、私はエラーが発生します。
Invoke-Sqlcmd : A network-related or instance-specific error occurred while establishing a connection to
SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and
that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 -
Could not open a connection to SQL Server)
At line:13 char:9
+ $data = Invoke-Sqlcmd -query $sqlcmd -Database $DBase -ServerInstance ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Invoke-Sqlcmd], SqlException
+ FullyQualifiedErrorId : SqlExectionError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
Invoke-Sqlcmd :
At line:13 char:9
+ $data = Invoke-Sqlcmd -query $sqlcmd -Database $DBase -ServerInstance ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Invoke-Sqlcmd], ParserException
+ FullyQualifiedErrorId : ExecutionFailureException,Microsoft.SqlServer.Management.PowerShell.GetScri
ptCommand
資格情報が正しいはずです。だから、書式設定が間違っているかもしれません?私は確信していません....
postgresに接続できるコマンドレットがないと思いますか? –
ネイティブなものはありませんが、どのADO.NETプロバイダでも機能する「フレームワーク」を作成しました。 https://github.com/MikeShepard/POSH_Ado。私はPostgres用のサブモジュールを書いていませんが、かなりシンプルでなければなりません。 –