Bug #35619 creating a MySql connection from toolbox generates an error
Submitted: 27 Mar 2008 17:35 Modified: 16 May 2008 13:17
Reporter: Fabio Ketmaier Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:5.2.1 OS:Windows (Visual studio 2005)
Assigned to: CPU Architecture:Any

[27 Mar 2008 17:35] Fabio Ketmaier
Description:
If you drag a mySql connection from toolbox onto a form a then you save the form, reopening it generates an error.
In form.designer.vb there is a few line like
        '
        'MySqlConnection1
        '
        Me.MySqlConnection1.ConnectionString = Nothing

and that is the source of error. if you change "= Nothing" with "= string.empty" and save the form, reopening it works fine, but the first change to form layout recreates the "= Nothing" string and the error.

How to repeat:
Create a new vs2005 vb project, drag a mysql connection from the toolbox on the empty form1 and close the form designer. Open the form designer again and you get the error.

Suggested fix:
Don't create Me.MySqlConnection1.ConnectionString = Nothing statement or trap the "Nothing" assignement
[4 Apr 2008 8:23] Tonci Grgin
Hi Fabio and thanks for your report. I believe it is in part duplicate of Bug#33020. Can you find any answers there?
[4 Apr 2008 15:00] Fabio Ketmaier
Sorry for english, be patient and try to understand. I don't thing my problem is part of nor douplicate of #33020. My system is fully working, I can use mySql connector either instatiating object via code or drawing it from toolbox and then assignign right properties via IDE property window. The problem is that if I create a mySqlConnection picking it from toolbox and putting it a form (empty or not don't care) and then I don't assign any value to connection string, I can save the form and close it in the designer; but if I try to reopen the form in the disigner, the error is there.
The problem arises from the following lines from Form1.designer.vb
        '
        'MySqlConnection1
        '
        Me.MySqlConnection1.ConnectionString = Nothing
If you change = Nothing with anything else (ie "", " ". string.Empty, ...) all seems to be ok; that's not really true, because if you use "" or String.Empty as a value for connection string, then you add a mysql command draggin it from toolbox, the line Me.MySqlConnection1.ConnectionString = Nothing is deleted from Form1.designer.vb. At this point if you remove the mysqlcommand from the form and save the form,  the line Me.MySqlConnection1.ConnectionString = Nothing is inserted again in the Form1.designer.vb and the error is there. It seems there is some confusion between String.Empty and Nothing in the connector code. You can't assign Nothing to connection string while you can assign String.Empty (or "" in VB)
I hope this can help, but if you simply try to do what i've described you can easily see the problem
Regards
[29 Apr 2008 10:31] Tonci Grgin
Fabio, I don't follow you at all... What did you drag onto the form and from where? I don't see MySQL connection in Toolbox nor there is a way to drag connection from Server Explorer...

So, what is it?
[29 Apr 2008 16:27] Fabio Ketmaier
I send you a file with the images of the problem
[29 Apr 2008 16:46] Fabio Ketmaier
Sorry Tony, i try to append a file to previous message but my file is 865 Kb and I dont know if it has ben appended. I try to ftp it to ftp://ftp.mysql.com/pub/mysql/upload/. but I was unable to do. Can I e-mail my zipped documentation to some address; or how can I send the file to you attention?
Regards Fabio
[29 Apr 2008 16:57] Fabio Ketmaier
Tony, don't hate me please. I try again to Ftp my bug-data-35619.zip document to ftp://ftp.mysql.com/pub/mysql/upload/, and this time I think I succeed. Can you get the file? Let me know.

Regards, fabio
[30 Apr 2008 8:52] Tonci Grgin
Fabio, never mind, it takes time to get used to bugsdb. Can you please cut important part of image and attach it to report?
[30 Apr 2008 9:14] Fabio Ketmaier
Docs for Bug #35619

Attachment: MySqlError.zip (application/x-zip-compressed, text), 437.60 KiB.

[30 Apr 2008 9:18] Fabio Ketmaier
I tried to attach a smaller file as you requested. This time it seems attachment is OK. Let me know
Fabio
[30 Apr 2008 11:14] Tonci Grgin
Fabio, thanks, all is fine now. I can confirm that exception on reload of solution is raised ("Value cannot be null. Parameter name: key") for the reasons you described. We should probably add Connection.ConnectionString = "" somewhere in plugin code...

Thanks for your interest in MySQL.
[30 Apr 2008 14:53] Fabio Ketmaier
Bug 35619 resolution code example

Attachment: CnnStringProperty.doc (application/msword, text), 22.00 KiB.

[30 Apr 2008 15:01] Fabio Ketmaier
Tony, I have just added a files with little VB code that is derived from a generalized ADO.Net Provider i wrote for my purposes; it shows a trivial solution that can be applied to the "my" bug. I you simply add a function called (exactly) ShouldSerializeConnectionString() that returns true if connection string is not null and not empty and false if connection string is nul or empty, the designer will not serialize the property unless the value is not valid. This resolves the problem; try to believe. The code appended is VB code, but it's easy to understand. I hope this may help
Regards, Fabio
[30 Apr 2008 18:13] Bogdan Degtyariov
patch

Attachment: patch35619.diff (application/octet-stream, text), 1.17 KiB.

[7 May 2008 15:45] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/46466
[7 May 2008 15:46] Reggie Burnett
Fixed in 5.1.6 and 5.2.2
[16 May 2008 13:17] MC Brown
A note has been added to the 5.1.6 and 5.2.2 changelogs:

When creating a connection, setting the ConnectionString property of MySqlConnection to NULL would throw an exception.