Oracle InvalidOperationException-尝试从表中选择时 [英] Oracle InvalidOperationException - When trying to select from a table

查看:70
本文介绍了Oracle InvalidOperationException-尝试从表中选择时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个参数表,其中有一个参数说明我的程序是否应该运行,我正在尝试获取该值以检查功能.

I've got a parameters table where I've got a parameter to say whether my program should run, I'm trying to get this value to check for a function.

这是功能

    private static bool shouldRun()
    {
        OracleCommand c = conn.CreateCommand();

        c.CommandText = "select value from parameters where lower(name) = lower('valuetocheck')"; // this one doesn't work
        //c.CommandText = "select 'Y' from dual"; - This one works
        c.CommandType = System.Data.CommandType.Text;

        OracleDataReader dr = c.ExecuteReader();

        dr.Read();

        string s = dr.GetString(0); // exception on this line

        return false;
    }

其他信息如下:

对关闭的对象无效的操作

Invalid operation on a closed object

我已经尝试从双选中进行选择,如您在上面看到的那样,它工作得很好,但是当我尝试运行实际查询时,它不喜欢它.我已经在SQL Developer中检查了查询,并且工作正常.

I've tried selecting from dual, as you can see above, which works perfectly fine, but when I try to run the actual query it doesn't like it. I've checked the query in SQL Developer and it works fine.

我已经浏览过SO和其他网站,关于此问题,我可以获得的唯一信息是该命令与连接没有关联,就像您在上面看到的那样.

I've had a look around SO and other websites and the only information I could get on this issue was that the command wasn't associated with a connection, which as you can see above it is.

我也尝试过做

OracleCommand c;
c.Connection = conn;

这也不起作用.

任何对此的深刻见解,谢谢!

Any insight into this would be great, thanks!

推荐答案

当Oracle给出此错误-对关闭的对象进行无效操作"时,通常发生的实际上是用户没有访问权限他们试图在数据库中访问的对象.检查您的连接字符串,并绝对确保该连接字符串中列出的用户确实对您的查询中的对象具有特权-在这种情况下,请读取对Parameters表的访问权限.

When Oracle gives this error - "Invalid Operation on a closed object", more often than not, what actually happens is that the user does not have access privileges to the objects they are trying to access in the database. Check your connection string and make absolutely sure that the user listed in that connection string does have privileges to the objects in your query - in this case, read access to the Parameters table.

这篇关于Oracle InvalidOperationException-尝试从表中选择时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆