troubleshooting Question

Powershell script v3 to query against Oracle having an error v2

Avatar of Zack
ZackFlag for Australia asked on
PowershellWindows Server 2008Oracle Database
2 Comments1 Solution729 ViewsLast Modified:
Hi EE,

I have the following script:


$userId = ''
$password = ''
$host2 = ''
$port = '1521'
$serviceName = ''

$constr = "User Id=$userId;Password=$password;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$host2)(PORT=$port))(CONNECT_DATA=(SERVICE_NAME=$serviceName)))"

$conn= New-Object Oracle.DataAccess.Client.OracleConnection($constr)
$sql="select * from dba_users"
$command = New-Object Oracle.DataAccess.Client.OracleCommand($sql,$conn)



When I run it get the error:

GAC    Version        Location
---    -------        --------
True   v2.0.50727     C:\Windows\assembly\GAC_64\Oracle.DataAccess\\Oracle.DataAccess.dll
Exception calling "Open" with "0" argument(s): "ORA-12514: TNS:listener does not currently know of service requested

in connect descriptor"
At C:\psscripts\CernerQuery.ps1:12 char:1
+ $conn.Open()
+ ~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : OracleException

Exception calling "ExecuteReader" with "0" argument(s): "Connection must be open for this operation"
At C:\psscripts\CernerQuery.ps1:15 char:1
+ $reader=$command.ExecuteReader()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : InvalidOperationException

You cannot call a method on a null-valued expression.
At C:\psscripts\CernerQuery.ps1:17 char:7
+ while($reader.Read()){
+       ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Any assistance is appreciated.

Thank you.
"Batchelor", Developer and EE Topic Advisor

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2015

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros