Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems reading from Oracle

I've just installed an Oracle express database and am trying to read some data from a table I've put in there:

using (OracleConnection conn = new OracleConnection("Data Source=localhost:1521/xe;Persist Security Info=True;User ID=SYSTEM;Password=SYSTEMPASSWORD"))
{
    OracleCommand command = new OracleCommand("SELECT * FROM Persons WHERE Firstname = 'John'", conn);
    conn.Open();
    OracleDataReader reader = command.ExecuteReader();

    try
    {
        while (reader.Read())
        {
            string strResult = reader.GetString(0);
        }
    }
    catch (OracleException oex)
    {
        MessageBox.Show(oex.Message, "Oracle error");
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error");
    }
    finally
    {
        reader.Close();
    }
} 

On the while (reader.Read()) it just quits since the reader does not hold any data. What is wrong? Connectionstring? I've run the same SELECT in the commandprompt tool that is installed with Oracle express and it works fine.

like image 373
Jason94 Avatar asked May 04 '12 13:05

Jason94


People also ask

Does Oracle allow dirty reads?

Comments. Nope, no dirty reads in Oracle. No blocking in Oracle either.

How can I improve my Oracle query performance?

Partitioning your data and creating local partitioned indexes can improve your query performance. On a partitioned table, each partition has its own set of index tables. Effectively, there are multiple indexes, but the results from each are combined as necessary to produce the final result set.

What is dirty read in Oracle?

Dirty Reads A dirty read is when you see uncommitted rows in another transaction. There is no guarantee the other transaction will commit. So when these are possible, you could return data that was never saved to the database! Dirty reads are impossible in Oracle Database.


1 Answers

First thing to do when connection to any system is see/test if it succeeded and after that continue. Without these simple kinds of tests your application is bound to behave like a time-bomb. A bit of defensive programming will make your projects a lot easier to debug. Not really the answer you are looking for but currently the state of the connection is not clear at query execution time.

like image 116
ik_zelf Avatar answered Nov 03 '22 10:11

ik_zelf