【问题标题】:Execute simple procedure call in Nhibernate在 Nhibernate 中执行简单的过程调用
【发布时间】:2018-04-16 14:43:30
【问题描述】:

我想在 NHibernate 中执行一个简单的 MySQL 存储过程调用,如下所示:

public void ExecuteProcedure(long idCell)
{
    using (ISession session = this.iSessionFactory.OpenSession())
    {
        using (ITransaction transaction = session.BeginTransaction())
        {
            try
            {
                string sQL = "call test(:idCell)";
                IQuery query = session.CreateSQLQuery(sQL);
                query.SetParameter("idCell", idCell);
                query.UniqueResult();
            }
            catch (Exception ex)
            {
                transaction.Rollback();
            }
        }
    }
}

下面是存储过程:

CREATE PROCEDURE `test`(IN `testing` BIGINT)
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''

BEGIN
    select * from tbcell where id = testing;
END

这会返回以下错误:

could not execute query
[ call test(?p0); ]
  Name:idCell - Value:18
[SQL: call test(?p0);]

怎么了?感谢您的帮助。

【问题讨论】:

  • 你能显示错误详情吗?
  • 感谢您关注纳杰拉。不幸的是,错误窗口中没有更多细节。
  • 这个命令(理论上)正确吗?还是有最好的方法来做到这一点?

标签: c# mysql stored-procedures nhibernate


【解决方案1】:

伙计们,我明白了。我正在访问远程用户的数据库,并且需要授予对存储过程的访问权限(我认为仅授予对架构的访问权限就足够了)。 nHibernate 没有返回有关权限的错误,因此,我没有将问题与此相关联。抱歉,感谢关注。

GRANT EXECUTE ON PROCEDURE myDB.Test TO 'testUser'@'192.168.101.100';
FLUSH PRIVILEGES;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-18
    • 1970-01-01
    • 2011-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多