<p>I am facing problem with an Oracle Query in a .net 2.0 based windows application. I am using <code>System.Data.OracleClient</code> to connect to oracle database. Name of database is <code>myDB</code>. Below the the connection string I am using:</p>

<pre><code>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
</code></pre>

<p>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):</p>

<pre><code>SELECT ID, NAME  
FROM MyTempTable
WHERE ID IN (10780, 10760, 11890)
</code></pre>

<p>But if I append the database name along with it the it is giving correct result:</p>

<pre><code>SELECT ID, NAME
FROM "myDB".MyTempTable
WHERE ID IN (10780, 10760, 11890)
</code></pre>

<p>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.</p>

[{'answer_id': 38022, 'author': 'skolima', 'author_id': 3205, 'author_profile': 'https://Stackoverflow.com/users/3205', 'pm_score': 0, 'selected': False, 'text': '<p>Try adding</p>\n\n<pre><code>CONNECT_DATA=(SID=myDB)(SERVICE_NAME=ORCL)\n</code></pre>\n\n<p>in the connection string.</p>\n'}, {'answer_id': 38050, 'author': 'stjohnroe', 'author_id': 2985, 'author_profile': 'https://Stackoverflow.com/users/2985', 'pm_score': 3, 'selected': True, 'text': '<p>This looks like an issue with name resolution, try creating a public synonym on the table:</p>\n\n<p>CREATE PUBLIC SYNONYM <em>MyTempTable</em> for <em>MyTempTable</em>;</p>\n\n<p>Also, what exactly do you mean by <strong>wrong result</strong>, incorrect data, error message?</p>\n\n<hr>\n\n<p>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.</p>\n'}, {'answer_id': 38306, 'author': 'Simon Munro', 'author_id': 3893, 'author_profile': 'https://Stackoverflow.com/users/3893', 'pm_score': 1, 'selected': False, 'text': '<p>For starters, I would suggest that you use the .net data providers from Oracle - if at all possible.  If you are starting off in a project it will be the best way to save yourself pain further down the line.  You can get them from <a href="http://www.oracle.com/technology/tech/windows/odpnet/index.html" rel="nofollow noreferrer">here</a>  </p>\n'}, {'answer_id': 40000, 'author': 'hamishmcn', 'author_id': 3590, 'author_profile': 'https://Stackoverflow.com/users/3590', 'pm_score': 1, 'selected': False, 'text': '<p>To expand on what stjohnroe has said it looks like the reason you are getting different results is because two different tables with the same name exist on different schemas.<br>\nBy adding the myDB username to the front of the query you now access the table with the data you are expecting. (Since you say the data doesn\'t belong on "myDB" this probably means the app/proc that is writing the data is writing to the wrong table too).<br>\nThe resolution is:<br>\n1. If the table really doesn\'t belong on "myDB" then drop it for tidyness sake (now you may get 904 table not found errors when you run your code)<br>\n2. Create a synonym to the schema and table you really want to access  (eg CREATE SYNONYM myTable FOR aschema.myTable;)<br>\n3. Don\'t forget to grant access rights from the schema that owns the table (eg: GRANT SELECT,INSERT,DELETE ON myTable TO myDB; (here myDB refers to the user/schema))  </p>\n'}, {'answer_id': 6239631, 'author': 'Gary Myers', 'author_id': 25714, 'author_profile': 'https://Stackoverflow.com/users/25714', 'pm_score': 2, 'selected': False, 'text': '<p>Upon connecting to the database issue am</p>\n\n<pre><code>ALTER SESSION SET CURRENT_SCHEMA=abc;\n</code></pre>\n\n<p>where abc is the user that owns the tables.</p>\n'}]
['https://Stackoverflow.com/questions/38014', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/191/']