Bug #40765 Connector net 5.2.4 Fatal error encountered during command execution
Submitted: 16 Nov 2008 20:14 Modified: 27 Sep 2010 8:05
Reporter: Neoh Royo Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:5.2.4 OS:Windows
Assigned to: CPU Architecture:Any
Tags: 5.2.4, FATAL ERROR

[16 Nov 2008 20:14] Neoh Royo
Description:
ExecuteReader() method of the MySqlCommand object displays "Fatal error encountered during command execution" message when the simple statement below is executed.

select @data := 3, @data * 4;

How to repeat:
MySqlConnection con = new MySqlConnection();
con.ConnectionString = "Database=sampledb;Data Source=localhost;User Id=root;Password=a";
con.Open();
// Connection ok
string cmdText = "select @data := 3, @data * 4;";
MySqlCommand cmd = new MySqlCommand(cmdText, con);
MySqlDataReader r = cmd.ExecuteReader();
r.Read();
MessageBox.Show(r.GetInt32(1).ToString());
r.Close();
con.Close();
r.Dispose();
con.Dispose();
[17 Nov 2008 16:26] Reggie Burnett
Neoh

This is not a bug.  You are attempting to use user variables in your sql.  The default mode for Connector/Net assumes you will not be using user variables (as most users don't) and so it sees @data and expects to find a parameter named @data.  When it doesn't find one it throws an exception.

To fix this add 'allow user variables=true' to your connection string.  In this mode it will not complain when it sees @data but doesn't find a parameter of that name.
[17 Nov 2008 22:17] Neoh Royo
Well thanks a lot. I really thought It was a bug. I usually include user variables in some of my queries and get no problem with connector/net 5.1.4. I never thought this feature will be disabled by default in higher versions. Thanks for the info, this really helped a lot.
[27 Apr 2010 10:07] avneesh mishra
thanks mr. Reggie Burnett
[14 May 2010 3:55] Bonifacio Penafiel
It really a big help guys...
[22 Sep 2010 2:35] loku Go
Could anyone tell me how to make that user variable set to true?

Dim conn
        conn = New MySqlConnection()
        myConnString = "server=" & TextBox1.Text & ";" _
    & "user id=" & TextBox3.Text & ";" _
    & "password=" & TextBox2.Text & ";" _
    & "database=" & TextBox4.Text

        conn.ConnectionString = myConnString

Dos it go somewhere here?
[22 Sep 2010 2:35] loku Go
Could anyone tell me how to make that user variable set to true?

Dim conn
        conn = New MySqlConnection()
        myConnString = "server=" & TextBox1.Text & ";" _
    & "user id=" & TextBox3.Text & ";" _
    & "password=" & TextBox2.Text & ";" _
    & "database=" & TextBox4.Text

        conn.ConnectionString = myConnString

Dos it go somewhere here?
[27 Sep 2010 8:05] Neoh Royo
Dim conn
        conn = New MySqlConnection()
        myConnString = "Data Source=" & TextBox1.Text & ";" _
    & "User Id=" & TextBox3.Text & ";" _
    & "Password=" & TextBox2.Text & ";" _
    & "Database=" & TextBox4.Text & ";" _
    & "Allow User Variables=True"

        conn.ConnectionString = myConnString