0

I'm using ODP.net with Powershell to execute query on my Oracle Database.

I want to time-out the execution of my query. This is my code :

[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

I want to add a timeout of 1minutes on this section of my code : $ExecuteQuery=$Query.ExecuteReader()

How can I do this? I can't find any cmdlet doing this...

Thanks

1

1 Answer 1

2

Use the CommandTimeout on the Command object returned from CreateCommand()

Example

$cmd=$OracleConnexion.CreateCommand()
$cmd.CommandText=$FluxSiebel
$cmd.CommandTimeout = 60; # 1 minute (60 seconds)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.