Database Reference
In-Depth Information
(CONNECT_DATA =
(SERVICE_NAME = xe)
)
)
2.
TNS entries can be browsed using a function as follows:
function Select-TNS
{
$enu = New-Object Oracle.DataAccess.Client.
OracleDataSourceEnumerator
Write-Output $enu.GetDataSources()
}
3.
Invoke Select-TNS to list all entries or pipe it to Where-Object to ilter it down:
Select-TNS | where-object {$_.InstanceName -like '*DEV*'} | ft
Reading connection strings from conig iles
1. Often connection strings are stored in app conig iles, such as the following:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="AppConnect"
connectionString="Data Source=LOCALDEV;User
Id=HR;Password=pass;Connection Timeout=10"/>
</connectionStrings>
</configuration>
You can easily read the connection string from such a ile as follows:
function Get-ConfigConnectionString(
[string] $filename = $(throw "filename is required"),
[string] $name = $(throw "connection string name is
required"))
{
$config = [xml](gc $filename)
$item = $config.configuration.connectionStrings.add | where
{$_.name -eq $name}
if (!$item) { throw "Failed to find a connection string with
name '{0}'" -f $name}
return $item.connectionString
}
$connectString = Get-ConfigConnectionString .\App.config
AppConnect
 
Search WWH ::




Custom Search