3

Below is my Oracle query which is running via PowerShell. It is working fine with no error if I am running it locally on that machine.

[Reflection.Assembly]::LoadFile("E:\oracle\product\11.2.0\ODP.NET\bin\2.x\Oracle.DataAccess.dll")

$constr = "User Id=system;Password=pass;Data Source=API"
$conn= New-Object Oracle.DataAccess.Client.OracleConnection($constr)
$conn.Open()
$sql="select * from dba_users"
$command = New-Object Oracle.DataAccess.Client.OracleCommand($sql,$conn)
$reader=$command.ExecuteReader()

while($reader.Read()){
  $reader.GetString(0)
}

$conn.Close()

I want to run same query on other machine from this machine. I can say I want to run it remotely.

When I run it I am getting this error:

Exception calling "Open" with "0" argument(s): "ORA-12541: TNS:no listener"

I can't add entry in Tnsora file.

Can anybody advise me any alternative way to achive this?

1 Answer 1

1

If you can't modify the tnsora, you have to use either EZConnect or the connect descriptor as your connection string. Try this:

$userId = 'system'
$password = 'pass'
$host = 'ip or hostname'
$port = '1521'
$serviceName = 'Your service name'

$constr = "User Id=$userId;Password=$password;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=$host)(PORT=$port))(CONNECT_DATA=(SERVICE_NAME=$serviceName)))"
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer. I will try and let you know.
One more question $serviceName = 'Your service name'. What do i need to put in service name. It would be database name or something else
Yes, the database name. For further information about the connect descriptor I suggested you to use, look at the link I provided you ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.