tags:

views:

39

answers:

3

I found that in my project order of named parameter has sense.

I call this procedure

CREATE PROCEDURE `test`.`TestProc` (
in myText varchar (5),
in myText2 varchar (100)
)
BEGIN

END

If I add parameters like this:

    command.CommandText = "testProc";
    command.CommandType = System.Data.CommandType.StoredProcedure;
    command.Parameters.AddWithValue("myText2", "aaaaaaaaaaaaaaaaa");
    command.Parameters.AddWithValue("myText", "bbbb");

I get "Data too long" exception. Also I can't reproduce this in test project.

Any thoughts?


I found the cause. Looks like bug in MySql .Nat Data Provider. To reproduce the bug you need to call this not under the root user.

Conclusion: MySql.Data version 6.2.3.0. Order of named parameter has sense If you call procedure with non root db account

+1  A: 

The name of the parameters don't have to match the columns but the placeholders:

INSERT INTO testproc (mytext, mytext2) VALUES (?mytext, ?mytext2)

I suppose if you use unnamed parameters:

INSERT INTO testproc (mytext, mytext2) VALUES (?, ?)

the order does matter.

I always used the former option but with:

command.Parameters.Add("?mytext2", "aaaaaaaaaaaaaaaaa")
command.Parameters.Add("?mytext", "bbbb")

Don't know if it makes any difference to AddWithValue()

Update: Just noticed that your parameters are missing a questionmark. That will be the problem. Add a questionmark to both, your query and your parameters.

SchlaWiener
I don't add parameters to query text. I've just edited my code to show how I call procedure.
Orsol
Sorry, I didn't paid enough attention to your first sql bits. It looked like a create table statement so I thought you wanted to query something ;)
SchlaWiener
A: 

The MySQL driver doesn't support named parameters. The name of the parameters are ignored, and they are applied in the order that you put them in the parameter collection.

Guffa
Sure? In test project all works fine independently of order.
Orsol
@Orsol: There may be differences between drivers. Are you using the same database server, the same driver and the same way to connect in the test project?
Guffa
All same. Database is not same, but I think it doesn't matters
Orsol
A: 

Answer that I get from MySql bugtracker:

Reggie Burnett

I don't believe this is a bug. I believe your test user doesn't have the privs to see the body of the proc. Please login to MySQL using the commandline client and the test user account. Do a "show create procedure" on your proc. If the body is null you need to use the "use function bodies=false" option and pass in the parameters in the right order.

Orsol