0

The following SQL runs as expected in the workbench, but generates an error "parameter @search must be defined" when I fire it in from a C# application. Can anyone explain this?

set @search = 'b%';
select * from country where Name like @search
1
  • 1
    How do you "fire it in from a C# application"? Can you show your code please. Commented Nov 8, 2016 at 14:49

1 Answer 1

2

MySQL use the @variable_name expression as a user defined variable. C# (or the provider - not really sure which) on the other hand uses the @parameter_name to annotate parameter placeholder in the query.

If you want to use sql user defined variables, then add the following parameter to the connection string of your .Net connector connection:

Allow User Variables=True

or

AllowUserVariables=True

This option was added to connector v5.2.2

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

2 Comments

Cool. Is there any reason to not do this? Why is it switched off by default?
Since I'm not a developer of MySQL's .net connector, I can only guess that more developers use parameters in the old fashioned @parameter_name convention, than MySQL user defined variables.

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.