Click here to Skip to main content
16,016,306 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hi
I have created a routine in mysql and it gets executed there and I am calling the routine from my code behind and I am the exception cannot find the procedure or routine in database

this is the code where i am calling the procedure
code where i am calling the routine:
C#
public int getLeaveReqId(string strAssId,string strLeaveStatus,string strLeaveType)
   {
       int leaveReqId = 0;
       Con = new MySqlConnection(conn);
       Con.Open();
       MySqlCommand cmdLeaveReqId = new MySqlCommand("sp_getLeaveId", Con);
       cmdLeaveReqId.Parameters.Add("@associateId", MySqlDbType.Int32).Value = Convert.ToInt32(strAssId.Trim());
       cmdLeaveReqId.Parameters.Add("@leavetype", MySqlDbType.String).Value = strLeaveType.Trim();
       cmdLeaveReqId.Parameters.Add("@leaveStatus", MySqlDbType.String).Value = strLeaveStatus.Trim();
       cmdLeaveReqId.CommandType = CommandType.StoredProcedure;
       MySqlDataReader drLeaveReqId = cmdLeaveReqId.ExecuteReader();
       drLeaveReqId.Read();
       leaveReqId = Convert.ToInt32(drLeaveReqId[0].ToString().Trim());
       Con.Close();
       return leaveReqId;
   }

Routine:
C#
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_getLeaveId`(
in associateId integer,
in leavetype varchar(45),
in leaveStatus varchar(45)
)
BEGIN
select leave_req_id from leave_request where leave_type_id = (select leave_type_id 
from leave_type where leave_type=leavetype) 
and leave_status_id=(select leave_status_id from leave_status where leave_status=leaveStatus) 
and associate_id=associateId;
END

stack trace:

C#
[MySqlException (0x80004005): Procedure or function '`sp_getLeaveId`' cannot be found in database '`kcube_intra`'.]
   lms_ApprovalOrRejection.lnkApprove_Click(Object sender, EventArgs e) in c:\Users\10033\Desktop\lms_17_01_2012\LeaveManagementSystem\lms_ApprovalOrRejection.aspx.cs:50
   System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +79
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Posted
Comments
manognya kota 19-Jan-12 0:38am    
did you check whether the connection string is pointing to the correct database?
Shashwath7 19-Jan-12 1:27am    
yes it is pointing to the correct Db only

could be:
1. connection pointing to wrong database
2. typo error of sp name
3. connection is pointing to a correct database name but different server
 
Share this answer
 
Comments
Shashwath7 19-Jan-12 2:18am    
<add name="Constr" connectionstring="dataSource=localhost;Initial Catalog=kcube_intra;uid=root;password=kcubeserver" providername="MySql.Data.MySqlClient"> this is my connection string details
Jephunneh Malazarte 19-Jan-12 9:31am    
did you try to execute a query to your database using your existing db connection and run the select statement to fetch all storedprocedure inside that db? if your sp is not there then maybe that's the reason.
Try the thread
http://bugs.mysql.com/bug.php?id=61249
It seems to be a connector problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900