从Oracle读取的问题

Jas*_*n94 6 c# oracle oracle11g

我刚刚安装了一个Oracle Express数据库,并试图从我放入的表中读取一些数据:

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();
    }
} 
Run Code Online (Sandbox Code Playgroud)

while (reader.Read())它刚刚退出,因为读者不包含任何数据.怎么了?Connectionstring?我在SELECT随Oracle Express一起安装的commandprompt工具中运行相同,并且工作正常.

ik_*_*elf 5

连接到任何系统时要做的第一件事是查看/测试是否成功,然后继续.如果没有这些简单的测试,您的应用程序必然会像定时炸弹一样运行.一些防御性编程将使您的项目更容易调试.不是你正在寻找的答案,但目前在查询执行时不清楚连接的状态.