1

I have a problem, I have stored procedure in my MySQL database called: sp_insertSupplier. This method is working when executed in mysql database.

I make this syntax in Save button

private void btn_supplier_save_Click(object sender, EventArgs e)
{
    string connections = Connection.mysqlconnectionbuilder();
    using (MySqlConnection conn = new MySqlConnection(connections))
    {
        using (MySqlCommand cmd = new MySqlCommand()) 
        {
            //make connection
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "call sp_insertSupplier(@KD,@NM,@AL,@EM,@TLP);";
            cmd.Parameters.AddWithValue("@KD", createCode()); 
            cmd.Parameters.AddWithValue("@NM", txtsuppliernama.Text); 
            cmd.Parameters.AddWithValue("@AL", txtsupplieralamat.Text); 
            cmd.Parameters.AddWithValue("@EM", txtsupplieremail.Text); 
            cmd.Parameters.AddWithValue("@TLP",txtsuppliernotelp.Text);
            try
            {
                conn.Open();
                int result = cmd.ExecuteNonQuery();
                //check the result status
                if (result.Equals(1))
                {
                    DialogResult results = MessageBox.Show("Data berhasil ditambahkan! \n Apakah anda ingin input data lainnya? ", "Sukses!", MessageBoxButtons.OKCancel);
                    //cek apabila ingin menambahkan data lagi.
                    if (results.Equals(DialogResult.OK))
                    {
                        reset();
                    }
                    else if (results.Equals(DialogResult.Cancel))
                    {
                        this.Close();
                    }
                }
            } //end TRY
            catch (Exception exe)
                {
                    MessageBox.Show("Terjadi Kesalahan", "Perhatian!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    StreamWriter _writer = new StreamWriter("E899911823.log");
                    _writer.WriteLine(exe.ToString());
                    Console.WriteLine(exe.ToString());
                } //END CATCH
            finally 
                {
                    conn.Clone();
                } //END FINALLY
        }
    }
}

but, when I execute the syntax, it shows an error:

MySql.Data.MySqlClient.MySqlException (0x80004005): Procedure or function '`call sp_insertSupplier(@KD,@NM,@AL,@EM,@TLP)`' cannot be found in database XXXXX

I don't think any problems with connection manager or the random method to create @KD.

I have still same problems, the console shows:

MySql.Data.MySqlClient.MySqlException (0x80004005): Procedure or function '`call sp_insertSupplier`' cannot be found in database '`XXXXX`'.
at MySql.Data.MySqlClient.ProcedureCache.GetProcData(MySqlConnection connection, String spName)
at MySql.Data.MySqlClient.ProcedureCache.AddNew(MySqlConnection connection, String spName)
at MySql.Data.MySqlClient.ProcedureCache.GetProcedure(MySqlConnection conn, String spName, String cacheKey)
at MySql.Data.MySqlClient.StoredProcedure.GetParameters(String procName, DataTable& proceduresTable, DataTable& parametersTable)
at MySql.Data.MySqlClient.StoredProcedure.CheckParameters(String spName)
at MySql.Data.MySqlClient.StoredProcedure.Resolve(Boolean preparing)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at SerbaManisInventory.SupplierAdd.btn_supplier_save_Click(Object sender, EventArgs e)

I just rewrite the code so that the code like this:

using (MySqlCommand cmd = new MySqlCommand()) 
{
    cmd.Connection = conn;
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.CommandText = "call sp_insertSupplier";
    cmd.Parameters.AddWithValue("@KD", createCode()); 
    cmd.Parameters.AddWithValue("@NM", txtsuppliernama.Text);
    cmd.Parameters.AddWithValue("@AL", txtsupplieralamat.Text); 
    cmd.Parameters.AddWithValue("@EM", txtsupplieremail.Text);
    cmd.Parameters.AddWithValue("@TLP",txtsuppliernotelp.Text); 
    try
        {
            ...

4 Answers 4

7

Make sure that your database name is all in lower case letters in your connection string! I got this error too and solved it by using this bug report, changing my database name to all lower case letters. Seems this behavior is not dependent on target system type.

Sign up to request clarification or add additional context in comments.

Comments

2
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "call sp_insertSupplier(@KD,@NM,@AL,@EM,@TLP);";

If the CommandType is a StoredProcedure, you don't need to write all that. Just write:

cmd.CommandText = "sp_insertSupplier";

And supply the parameters as you did.

There is indeed no procedure/function named call sp_insertSupplier(@KD,@NM,@AL,@EM,@TLP);

2 Comments

remove this call . Just write sp_insertSupplier
oops, i forgot that "call" :D thanks for your help buddy! have a great time then! working now.
2

Just write the name of the stored procedure in the CommandText

  cmd.CommandText = "sp_insertSupplier";

In the way you write the CommandText you are forcing the provider to search a storedprocedure with a name composed by "call sp_insertSupplier ......" and obviously there is no procedure with that name

2 Comments

the problem is still persist. What possibilities that make this error?
From the stack trace you still have the word 'call' in front of the storedprocedure real name. Do not put anything before and after the name of the sp
0

just write the name of the stored procedure in the commandText cmd.CommandText = "sp_insertSupplier"; you don't need the "call" part

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.