Click here to Skip to main content
15,665,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

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);
MySqlCommand cmd = new MySqlCommand("sp_getUserCredentials(" + Username.Trim() + "," + Password.Trim() + ")", con);
cmd.CommandType = CommandType.StoredProcedure;
int count = Convert.ToInt32(cmd.ExecuteScalar());
return count;

1) Please don't do it like that. You leave yourself wide open to problems of all sorts, including SQL Injection attacks which could destroy your database. Use Parametrized queries instead.
MySqlCommand cmd = new MySqlCommand("sp_getUserCredentials(@UN, @PW)", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UN", Username.Trim());
cmd.Parameters.AddWithValue("@PW", Password.Trim());
int count = Convert.ToInt32(cmd.ExecuteScalar());

2) Never store passwords in clear text - it is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^]

These won't fix your problem immediately, but they do need doing.
Share this answer
Is your Store Procedure accept parameter?
Where are you passing them?
Share this answer
Prasad_Kulkarni 13-Jan-12 3:19am    
it is comment not an answer. post it as comment

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