超时 powershell 命令

Timeout powershell command

我正在使用 ODP.net 和 Powershell 在我的 Oracle 数据库上执行查询。

我想暂停查询的执行。这是我的代码:

[void][System.Reflection.Assembly]::LoadFile("C:\Oracle.ManagedDataAccess.dll")
$OracleConnexion = New-Object Oracle.ManagedDataAccess.Client.OracleConnection('User Id=test;Password="test";Data Source=10.0.0.0/TEST')

$FluxSiebel = "SELECT * FROM BLABLA"

Try { 

    $OracleConnexion.Open()

}Catch { 

    Write-Output "Connection KO"
    $OracleConnexion
    Exit 2
}


$Query=$OracleConnexion.CreateCommand()
$Query.CommandText=$FluxSiebel

$TimeTaken=  (Measure-Command  {

    $ExecuteQuery=$Query.ExecuteReader()

}).TotalMilliseconds | Out-String

我想在代码的这一部分添加 1 分钟的超时:$ExecuteQuery=$Query.ExecuteReader()

我该怎么做?我找不到执行此操作的任何 cmdlet...

谢谢

对从 CreateCommand() 返回的命令对象使用 CommandTimeout

例子

$cmd=$OracleConnexion.CreateCommand()
$cmd.CommandText=$FluxSiebel
$cmd.CommandTimeout = 60; # 1 minute (60 seconds)