简体   繁体   English

Oracle参数与Dapper问题

[英]Oracle parameter with Dapper issue

I am struggling with using ORACLE parameters via DAPPER. 我正在努力通过DAPPER使用ORACLE参数。 The error message received is "ORA-00942: table or view does not exist". 收到的错误消息是“ ORA-00942:表或视图不存在”。

However the code works without the parameter, and I suspect that this is a simple Oracle parameter syntax issue. 但是,代码无需参数即可工作,我怀疑这是一个简单的Oracle参数语法问题。 The code follows: 代码如下:

    public List<ForecastData>GetByFiscalYear(string fiscalYear)
    {
        List<ForecastData> queryResults = new List<ForecastData>();

        String sqlQuery = @"SELECT RES.FISCALYEAR year FROM RESOURCE_AVAILABILITY RES WHERE RES.FISCALYEAR = :p_fiscalYear";

        using (var oraCon = new OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Oracle_HRZD"].ToString()))
        {
            oraCon.Open();
            queryResults = oraCon.Query<ForecastData>(sqlQuery, new { p_fiscalYear = fiscalYear }).ToList();
        }

        return new List<ForecastData>(queryResults);
    }

Any assistance will be greatly appreciated... 任何帮助将不胜感激...

Usually, ORA-00942 is exactly what it says, it can't find the table/view (RESOURCE_AVAILABILITY) you are selecting from. 通常,ORA-00942就是它所说的,它找不到您要选择的表/视图(RESOURCE_AVAILABILITY)。 So it's not in the schema for the user you log on as or the user has not been granted SELECT on the table/view if it's another schema. 因此,它不在您登录时所使用的用户的架构中,或者如果该用户是另一个架构,则该用户尚未在表/视图上被授予SELECT权限。

But you say that if you remove WHERE RES.FISCAL_YEAR :p_fiscalyear , then it works. 但是您说如果删除WHERE RES.FISCAL_YEAR :p_fiscalyear ,那么它将起作用。 So it seems like you have select permissions on the table. 因此,似乎您对表具有选择权限。 Do you mean remove the whole where selection or have you tested enter a fixed string, as in WHERE RES.FISCAL_YEAR='2016' ? 您是要删除整个选择区域,还是已测试输入固定的字符串,例如WHERE RES.FISCAL_YEAR='2016'

My other top tip is to run Wireshark and look at what really is sent to the database, usually you connect on port 1521 filter on that. 我的另一个最重要的技巧是运行Wireshark并查看实际发送到数据库的内容,通常情况下,您需要在端口1521过滤器上进行连接。

The answer was to use the fully-qualified database-object name, including the schema. 答案是使用标准的数据库对象名称,包括架构。 Thanks for your assistance. 谢谢你的协助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM