stevenjin 2022-01-20 15:28 采纳率: 96.8%
浏览 53
已结题

使用dapper,在mysql调用存储过程时,提示在数据库中找不到存储过程或函数

C# 使用dapper,在mysql调用存储过程时,提示在数据库中找不到存储过程或函数
一、创建存储过程

Delimiter $$
drop PROCEDURE if EXISTS pro_test;
create PROCEDURE pro_test(in idIn int)
begin
select count(1) as Count from tch_teacher where id > idIn;
end $$
Delimiter ;

Delimiter $$
drop PROCEDURE if EXISTS pro_test1;
create PROCEDURE pro_test1(in idIn int, out count int)
begin
select count(1) into count from tch_teacher where id > idIn;
select * from tch_teacher where id > idIn;
end $$
Delimiter ;

call pro_test(11);

set @count =0;
call pro_test1(11, @count);
select @count;

二、调用

//方法一
sql = "call pro_test(@id);";
var res = conn.Query<int>(sql, new { id = 15 }).FirstOrDefault();  //85
Console.WriteLine("res = " + res);  //res = 85

//方法二
var param = new DynamicParameters();
param.Add("@idIn", 20);
param.Add("@count", 0, DbType.Int32, ParameterDirection.Output);
var res2 = conn.Query<Tch_Teacher>("pro_test1", param, null, true, null, CommandType.StoredProcedure);//res2.Count = 80
Console.WriteLine("Query count = " + param.Get<object>("@count"));   //Query count = 80

  • 写回答

3条回答 默认 最新

  • DarkAthena ORACLE应用及数据库设计方案咨询师 2022-01-20 15:38
    关注

    看下是不是用的同一个用户连接的同一个数据库

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 2月1日
  • 已采纳回答 1月24日
  • 创建了问题 1月20日