Advertisement
Guest User

Untitled

a guest
Feb 26th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. add-type -AssemblyName System.Data.OracleClient
  2.  
  3. $username = "XXXX"
  4. $password = "XXXX"
  5. $data_source = "XXXX"
  6. $connection_string = "User Id=$username;Password=$password;Data Source=$data_source"
  7.  
  8. $statement = "select level, level + 1 as Test from dual CONNECT BY LEVEL <= 10"
  9.  
  10. try{
  11. $con = New-Object System.Data.OracleClient.OracleConnection($connection_string)
  12.  
  13. $con.Open()
  14.  
  15. $cmd = $con.CreateCommand()
  16. $cmd.CommandText = $statement
  17.  
  18. $result = $cmd.ExecuteReader()
  19. # Do something with the results...
  20.  
  21. } catch {
  22. Write-Error (“Database Exception: {0}`n{1}” -f `
  23. $con.ConnectionString, $_.Exception.ToString())
  24. } finally{
  25. if ($con.State -eq ‘Open’) { $con.close() }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement