3

Execute mysql stored procedure

  var affectedRows = 
      context.Database.ExecuteSqlCommand("exec UpdateStatus @p_customerId, @p_id",
            new MySqlParameter("p_customerId", "006"),
            new MySqlParameter("p_id", 9));

Get MySqlException

An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in EntityFramework.dll

Additional information: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'exec UpdateStatus '006', 9' at line 1

When I try to replace stored procedure name with a Update statement it works. But I want to call a stored procedure instead.

I tried using Entity Framework 5 and 6 same error

0

1 Answer 1

1

MySQL Syntax of calling Stored Procedure from command is "CALL ". Also the parameters names should be having "@" in front.

So you need to change the code as as following.

var affectedRows = 
  context.Database.ExecuteSqlCommand("CALL UpdateStatus (@p_customerId, @p_id)",
        new MySqlParameter("@p_customerId", "006"),
        new MySqlParameter("@p_id", 9));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.