Database Reference
In-Depth Information
How to do it...
1.
The Oracle Data Provider for .NET ( ODP.NET ) is included with ODAC in Oracle.
DataAccess.dll and is generally the best choice for accessing Oracle. The irst
step is loading this library into memory:
$odpAssemblyName = "Oracle.DataAccess, Version=2.112.3.0,
Culture=neutral, PublicKeyToken=89b483f429c47342"
[System.Reflection.Assembly]::Load($odpAssemblyName)
GAC Version Location
--- ------- --------
True v2.0.50727 C:\Windows\assembly\GAC_32\Oracle.DataAccess
\2.112.3.0__89b483f429c47342\Oracle.DataAccess.dll
2.
Once the assembly is loaded you can start creating types. If you are not sure what
object types are available, use the following code to enumerate public types in the
Oracle.DataAccess assembly.
$asm = [appdomain]::currentdomain.getassemblies() | where-object
{$_.FullName -eq $odpAssemblyName}
$asm.GetTypes() | Where-Object {$_.IsPublic} | Sort-Object {$_.
FullName } | ft FullName, BaseType | Out-String
3.
With the assembly loaded, and the types to create known, you can now start creating
objects. A logical place to start is with a connection object:
$conn = New-Object Oracle.DataAccess.Client.OracleConnection
How it works...
First the .NET Framework's Assembly.Load method is called and a fully qualiied assembly
name is speciied. By default PowerShell 2.0 runs against the .NET Framework 2.0 so the 2.x
version of Oracle.DataAccess is speciied in $odpAssemblyName . The parts of the assembly
name can be found by inspecting %WINDIR%\assembly\ in Windows Explorer. Because the
output was not explicitly captured or discarded, details of the loaded assembly are shown.
Next, the AppDomain.CurrentDomain.GetAssemblies method is invoked and the list is
iltered down to the Oracle.DataAccess assembly. This veriies that the assembly loaded and
provides a reference to it. Finally it gets the types in that assembly, narrows them down by
public types, sorts the data by full name, and formats the resulting table with the full name
and base type properties of each Oracle type that is available.
 
Search WWH ::




Custom Search