Database Reference
In-Depth Information
5.
Create a connection function with built-in Help documentation, and a connection
method to connect via TNS:
<#
.SYNOPSIS
Connects to oracle via a connection string.
.DESCRIPTION
Creates a new Oracle Connection and opens it using the specified
connections string.
Created connection is stored and not returned unless -PassThru is
specified.
.PARAMETER ConnectionString
The full connection string of the connection to be created and
opened.
.PARAMETER PassThru
If -PassThru is supplied, the created connection will be returned
and not stored.
.EXAMPLE
Connect to oracle with a connection string and store the
connection for later use without outputting it.
Connect "Data Source=LOCALDEV;User Id=HR;Password=Pass"
.NOTES
If -PassThru isn't used, the connection will be available for
later operations such as Disconnect, without having to pass it.
#>
function Connect {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)] [string]$ConnectionString,
[Parameter(Mandatory=$false)] [switch]$PassThru )
$conn= New-Object Oracle.DataAccess.Client.OracleConnection($C
onnectionString)
$conn.Open()
if (!$PassThru) {
$SCRIPT:conn = $conn
Write-Verbose ("Connected with {0}" -f $conn.
ConnectionString)
}
else {
$conn
 
Search WWH ::




Custom Search