2016-02-26 197 views
0

我使用Powershell的ODP.net在我的Oracle數據庫上執行查詢。超時powershell命令

我想暫停執行我的查詢。這是我的代碼:

[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的這樣......

感謝

+0

https://開頭的文檔。 oracle.com/cd/E51173_01/win.122/e17732/OracleCommandClass.htm#DAFBGECA? –

回答

2

使用Command對象將CommandTimeout從CreateCommand()返回

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