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