C# .NET - call stored procedure in Mysql - Asked By abinav shankar on 13-Jan-12 03:04 AM

Hi

i have to call a Stored procedure and when i use the code given below i am getting an exception
Procedure or function '`sp_getUserCredentials(aasdasd,asdasd)`' cannot be found in database '`kcube_intra`'.
pl tell me where i am wrong


MySqlConnection con = new MySqlConnection(conn);

con.Open();

MySqlCommand cmd = new MySqlCommand("sp_getUserCredentials(" + Username.Trim() + "," + Password.Trim() + ")", con);

cmd.CommandType =

CommandType.StoredProcedure;

int count = Convert.ToInt32(cmd.ExecuteScalar());

return count;

kalpana aparnathi replied to abinav shankar on 30-Jan-12 09:32 PM
It was due to how you set up your connection string. The database needs to be specified in all lower-case,may 
be to match the name of the database as stored in MySQL. you didn't expect that to occur, since MySQL is otherwise case-insensitive on Windows.
Sri K replied to abinav shankar on 13-Jan-12 03:38 AM
It's almost identical to how you would call a SQL Server Stored Procedure:
 
using(MySqlConnection conn = new MySqlConnection(connString))
{
  MySqlCommand command = new MySqlCommand("spSomeProcedure;", conn);
  command.CommandType = System.Data.CommandType.StoredProcedure;
 
  // Add your parameters here if you need them
  command.Parameters.Add(new MySqlParameter("someParam", someParamValue));
 
  conn.Open();
 
  int result = (int)command.ExecuteScalar();
}
Anoop S replied to abinav shankar on 13-Jan-12 03:56 AM
The error simply says it cant find the specified stored procedure in the database. the reasons may be many. Like you dont have sp created on database or connection string is wrong,etc.
As a start can you try executing the Stored procedure directly in Query Analyser by passing parameter values?