locked
Problem with stored procedure in Data Access Layer RRS feed

  • Question

  • User127213263 posted

    Hi All,

    I've weird problem with stored procedure in Data Access Layer. Stored Procedure which is used in Data Access Layer is unable to recognize stored procedure in MySQl. When I replace stored procedure with Insert statement it is working good.

    Please find code below for reference.

    try
                {
                    con.Open();
    
                    MySqlCommand cmd = new MySqlCommand("InsertUsers", con);
    cmd.Parameters.Add(new MySqlParameter("?p_FirstName", FirstName));
                    cmd.Parameters.Add(new MySqlParameter("?p_LastName", LastName));
                  cmd.CommandType = CommandType.StoredProcedure;
    
                    cmd.ExecuteNonQuery();
     }
    
                catch (MySqlException ex)
                {
                    string msg = "Insert Error:";
                    msg += ex.Message;
                    throw new Exception(msg);
                }
    
                finally
                {
                    con.Close();
                }


    Insert Error:Procedure or function '`InsertUsers`' cannot be found in database '`UsersDB`'.




    Wednesday, December 12, 2012 11:42 AM

Answers

  • User-1716253493 posted

    Check the CASE of table name, stored procedure name etc, maybe mysql is case sensitive.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 13, 2012 1:38 AM

All replies

  • User-802546231 posted

    you need to tell the cmd object it is a stored procedure

    cmd.CommandType = CommandType.StoredProcedure;

    Wednesday, December 12, 2012 11:47 AM
  • User127213263 posted

    Hi Acula, Thanks for your response. That I already mentioned in my code...

    Wednesday, December 12, 2012 12:35 PM
  • User-1716253493 posted

    Check the CASE of table name, stored procedure name etc, maybe mysql is case sensitive.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 13, 2012 1:38 AM
  • User127213263 posted

    Hi Thanks  a lot you really saved my day, Well I had a problem with the database name in web.config. I've kept  Captials in database name in web.config. When I removed it. It worked like a charm... Anyway Thanks once again. Have a great day!!!  

    Thursday, December 13, 2012 2:11 AM
  • User-1716253493 posted

    I never use mysql, i just try analyst your problem. I look to your code is fine, and you said Insert statement working good

    Thursday, December 13, 2012 2:51 AM