I am facing problem with an Oracle Query in a .net 2.0 based windows application. I am using System.Data.OracleClient to connect to oracle database. Name of database is myDB. Below the the connection string I am using:
Data Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP) (HOST = 172.16.0.24)(PORT = 1522)))(CONNECT_DATA =(SERVICE_NAME = ORCL))); User ID=myDB;Password=myDB;Unicode=True
If I run the below query then it will given me wrong result (here wrong result means incorrect data. The data doesn’t belongs to myDB):
SELECT ID, NAME FROM MyTempTable WHERE ID IN (10780, 10760, 11890)
But if I append the database name along with it the it is giving correct result:
SELECT ID, NAME FROM 'myDB'.MyTempTable WHERE ID IN (10780, 10760, 11890)
My limitation is that I cannot append the database name as this is a generic application and can run with any database on run time. Please help.
This looks like an issue with name resolution, try creating a public synonym on the table:
CREATE PUBLIC SYNONYM MyTempTable for MyTempTable;
Also, what exactly do you mean by wrong result, incorrect data, error message?
Edit: What is the name of the schema that the required table belongs to? It sounds like the table that you are trying to select from is in a different schema to the one that belongs to the user you are connecting as.