ODP.net + VB = 未找到表

发布于 2024-11-03 17:14:22 字数 403 浏览 4 评论 0原文

我是 Oracle 新手,刚刚安装了 Oracle 10g XE 及其适用于 .NET 的 ODAC 包。 我正在 VB 中制作一个简单的连接和获取表应用程序,但是,它总是抛出“找不到表”错误。

我在 Oracle Home(Web 管理工具)中创建了“测试”表,这是我在 VB 中使用的代码:

    Dim oraCmd As New OracleCommand("Select * From Test")
    oraCmd.Connection = oraCon

    oraCon.Open()

    oraCmd.ExecuteReader()
    'Reader code supressed

编辑 当我在数据库主页中尝试相同的查询时,它有效。

I am new to Oracle and I have just installed Oracle 10g XE,and its ODAC package for .NET.
I am making a simple connect-and-get-table app in VB,however,it always throws a "Table not found" error.

I created the "Test" table in Oracle Home (the web admin thing) and here is the code I'm using in VB :

    Dim oraCmd As New OracleCommand("Select * From Test")
    oraCmd.Connection = oraCon

    oraCon.Open()

    oraCmd.ExecuteReader()
    'Reader code supressed

EDIT When I try the same query in Database Home, it works.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情深如许 2024-11-10 17:14:22

如果您在 Oracle 中使用不同的用户登录,并且想要从不同用户下的表中读取数据,则应该完全限定您的表名。如果您的表是在名为“TEST_USER”的用户下创建的,则将您的表查询为“Select * From TEST_USER.test”

当使用创建表的相同用户名登录时,这对我有用:

    private const string connString = "DATA SOURCE=//server:port/service_name;PASSWORD=pswd;USER ID=user_name;";

    static void Main(string[] args)
    {
        OracleConnection conn = new OracleConnection(connString);
        conn.Open();

        OracleCommand cmd = new OracleCommand("select * from test", conn);

        // This would also work if the username I used to login was "TEST_USER".
        // OracleCommand cmd = new OracleCommand("select * from TEST_USER.test", conn);

        cmd.ExecuteReader();

        conn.Close();
    }

另一个可能的问题是您用小写字母将表命名为“Test”,而不是在数据库中将其命名为“TEST”。在这种情况下,您需要引用带有引号的表,如下所示:

    static void Main(string[] args)
    {
        OracleConnection conn = new OracleConnection(connString);
        conn.Open();

        OracleCommand cmd = new OracleCommand("select * from \"Test\"", conn);
        cmd.ExecuteReader();

        conn.Close();
    }

或者,如果大小写是问题并且您想以这种方式解决它,您也可以在 Oracle 中重命名表:

ALTER TABLE "Test" RENAME TO TEST;

If you're logging in using a different user in oracle, and want to read from a table under a different user, you should fully qualify your table name. If your table is created under a user named "TEST_USER", then query your table as "Select * From TEST_USER.test"

This works for me when logged in under the same username of which the table was created:

    private const string connString = "DATA SOURCE=//server:port/service_name;PASSWORD=pswd;USER ID=user_name;";

    static void Main(string[] args)
    {
        OracleConnection conn = new OracleConnection(connString);
        conn.Open();

        OracleCommand cmd = new OracleCommand("select * from test", conn);

        // This would also work if the username I used to login was "TEST_USER".
        // OracleCommand cmd = new OracleCommand("select * from TEST_USER.test", conn);

        cmd.ExecuteReader();

        conn.Close();
    }

The other possible issue is that you named your table with lowercase letters as "Test", instead of it being named "TEST" in the database. In that case, you'll need to reference the table with quotes around it as such:

    static void Main(string[] args)
    {
        OracleConnection conn = new OracleConnection(connString);
        conn.Open();

        OracleCommand cmd = new OracleCommand("select * from \"Test\"", conn);
        cmd.ExecuteReader();

        conn.Close();
    }

Or you could also, rename your table in oracle if case is the issue and you want to resolve it this way:

ALTER TABLE "Test" RENAME TO TEST;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文