Bug #15830 connection unexpectedly terminated
Submitted: 17 Dec 2005 20:21 Modified: 3 May 2006 19:39
Reporter: Juergen Otto Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:1.07/1.06 OS:Microsoft Windows (Windows XP)
Assigned to: CPU Architecture:Any

[17 Dec 2005 20:21] Juergen Otto
Description:
The following insert-command produces the exception:

---------------------------------
'23000 Column 'id' cannot be null
---------------------------------

command.CommandText = "create table demo (id int, primary key (id))";
command.ExecuteNonQuery();

command.Parameters.Add("id", MySqlDbType.Int32);
command.Parameters["id"].Value = 1;
command.CommandText = "insert into demo (id) values (@id)";
command.ExecuteNonQuery();

The error does _not_ occur:
- if I don't use parameters, for example: insert into demo (id) values (1)
- if I dont' use primary key: create table demo (id int)

I use C# in Visual Studio 2003, Framework 1.1, Connector 1.07/1.04 with MySQL 5.0.16

Additional info: using 'not null' produces the same error: "create table demo (id int not null, primary key (id))"

Juergen Otto

How to repeat:
Use the above C# code in a Visual Studio 2003 (Framework 1.1) environment. The connection and command object must be created before.
[18 Dec 2005 13:17] Juergen Otto
Please correct the following line:

cancel: command.Parameters.Add("id", MySqlDbType.Int32);
instead: command.Parameters.Add("@id", MySqlDbType.Int32);

This is the way I use with Microsoft SQL Server and it also worked properly with the ByteFX-Driver for a long time. So I can write the same code for both DBMS using the IDbConnection-Interface.
[18 Dec 2005 16:07] Vasily Kishkin
Sorry...maybe I misuderstood you, but I was not able to reproduce the bug. Could you please create and attach your test case ?
[18 Dec 2005 21:12] Juergen Otto
C# project to reproduce the exception

Attachment: MySQL15830.zip (application/x-zip-compressed, text), 24.46 KiB.

[18 Dec 2005 21:16] Juergen Otto
Attached MySQL15830.zip is the C# project which should result in the exception described.

By the way. If I use Connector/Net 1.07 the statement connection.Open() in this project ends with an exception in german: "An existing connection was cancelled by the host computer."
[2 Jan 2006 13:00] Vasily Kishkin
Sorry...but you are not avaible to use @ in parameters, please replace @ on ? and try to test your code:

command.Parameters.Add("?id", MySqlDbType.Int32);
command.Parameters["?id"].Value = 1;
command.CommandText = "insert into demo (id) values (?id)";
command.ExecuteNonQuery();
[2 Jan 2006 19:20] Juergen Otto
Hello,

yes, it works using the ? Parameter.

But up to Version 1.04 the @ Parameter worked also,
so you could write the same code for different database systems
using the IDbConnection Interface:

--------------------
IDbDataParameter parameter;
parameter = command.CreateParameter();

parameter.ParameterName = "@x";
parameter.DbType = DbType.Int32;
parameter.Value = 1;
command.Parameters.Add(parameter);

command.CommandText = "insert into demo2 (id) values (@x)";
command.ExecuteNonQuery();
--------------------

Something must have changed.

I found the @ Parameter in several books and articles.
[2 Jan 2006 19:54] Juergen Otto
Sorry,

there is a small mistake in my comment.

1) The problem is not especially Version 1.04. It was the ByteFX-Driver which worked fine with the @ Parameter.

2) The @ Parameter works fine using Access and MS SQL Server
[5 Jan 2006 21:29] Juergen Otto
Hi,

thank you an sorry. I found the small sentence in the documentation now.

Could you please please help me about this exception on a simple con.Open(): "Connection unexpectedly terminated".

What did you change since Version 1.06?

The 1.05 dll makes no problems with a simple con.Open()

Many thanks in advance.

Juergen
[12 Jan 2006 22:02] Vasily Kishkin
Could you please provide more info about the bug. I mean some test case.
[13 Jan 2006 13:12] Juergen Otto
Test case to reproduce 'connection unexpectedly terminated'

Attachment: MySQL15830.exe (application/octet-stream, text), 72.87 KiB.

[13 Jan 2006 13:17] Juergen Otto
Try the button "Simple connect" in my test case, wait for the error and try the button again. The second time it works fine.

I use .Net Framework 1.1 and Visual Studio 2003 7.1.3088 (German).

connection.Open() produces the error 'connection unexpectedly terminated.

The error only occurs in the Visual Studio environment. No problems running the exe directly.

It happens only with Connector 1.06 and 1.07. Older versions work fine.

I tried it on server 4.1.2 and 5.0.16. Both the same result.
[23 Feb 2006 18:08] Reggie Burnett
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

Additional info:

Juergen,

If you want to use the @ for your parameters, you can add "old syntax=yes" to your connection string.  You should read the documentation about the issues with doing this.
[23 Feb 2006 19:18] Juergen Otto
Hello,

I think there is a small misunderstanding, because I changed in this thread to another problem.

1) The issue using the ? Parameter is cleared. Thank you.

2) But the heavy problem about "connection unexpectedly terminated" is still present. Please see my test case from 13 January. It happens only with Version 1.06 and 1.07.

Thank you

J├╝rgen Otto
[3 Apr 2006 19:39] Tonci Grgin
Hi. I've done testing on:
  Win XP SP2
  VS2005
  Connector 1.0.7.30072
  Several MySQL server versions on windows and linux
  and 
  Net 2.0
and I could not repeat the error you get. 

Since the only difference is in Microsoft software (newer VS and Net) I think it could be something they fixed in new releases.
[3 May 2006 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".