Bug #29123 Connection String grows with each use resulting in OutOfMemoryException
Submitted: 14 Jun 2007 22:44 Modified: 2 Jul 2007 5:06
Reporter: mohit srivastava Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:5.0.7 OS:Microsoft Windows
Assigned to:
Tags: connector, Memory, outofmemoryexception

[14 Jun 2007 22:44] mohit srivastava
Description:
In the following code, I simply try to use the same connection string multiple times.  This is fairly typical usage.  Each time, however, the connection string returned by MySqlConnection has an additional Database=caddr appended to it.

The following code
            for (int i = 0; i < 10; i++) {
                using (MySqlConnection conn = new MySqlConnection("Initial Catalog=caddr;User Id=root;Password=<hidden>;Logging=false;Connect timeout=30;pooling=false;")) {
                    conn.Open();
                    Console.WriteLine(conn.ConnectionString);
                }
            }

erroneously outputs the following
initial catalog=caddr;user id=root;logging=false;connect timeout=30;pooling=fals
e;Database=caddr
initial catalog=caddr;user id=root;logging=false;connect timeout=30;pooling=fals
e;Database=caddr;Database=caddr
initial catalog=caddr;user id=root;logging=false;connect timeout=30;pooling=fals
e;Database=caddr;Database=caddr;Database=caddr
initial catalog=caddr;user id=root;logging=false;connect timeout=30;pooling=fals
e;Database=caddr;Database=caddr;Database=caddr;Database=caddr
initial catalog=caddr;user id=root;logging=false;connect timeout=30;pooling=fals
e;Database=caddr;Database=caddr;Database=caddr;Database=caddr;Database=caddr
initial catalog=caddr;user id=root;logging=false;connect timeout=30;pooling=fals
e;Database=caddr;Database=caddr;Database=caddr;Database=caddr;Database=caddr;Dat
abase=caddr
initial catalog=caddr;user id=root;logging=false;connect timeout=30;pooling=fals
e;Database=caddr;Database=caddr;Database=caddr;Database=caddr;Database=caddr;Dat
abase=caddr;Database=caddr
initial catalog=caddr;user id=root;logging=false;connect timeout=30;pooling=fals
e;Database=caddr;Database=caddr;Database=caddr;Database=caddr;Database=caddr;Dat
abase=caddr;Database=caddr;Database=caddr
initial catalog=caddr;user id=root;logging=false;connect timeout=30;pooling=fals
e;Database=caddr;Database=caddr;Database=caddr;Database=caddr;Database=caddr;Dat
abase=caddr;Database=caddr;Database=caddr;Database=caddr
initial catalog=caddr;user id=root;logging=false;connect timeout=30;pooling=fals
e;Database=caddr;Database=caddr;Database=caddr;Database=caddr;Database=caddr;Dat
abase=caddr;Database=caddr;Database=caddr;Database=caddr;Database=caddr

How to repeat:
see above

Suggested fix:
This is a side effect of the connection string caching in the connector.

One solution is to remove connection string caching.  Alternatively, only allow Database=x to be appended once.
[19 Jun 2007 8:40] Tonci Grgin
Hi Mohit and thanks for your report.

Verified as described with
 - MySQL server 5.0.44BK on WinXP Pro SP2 localhost
 - c/NET 5.0.8 and .NET fw 2.0

In 10th iteration output is:
10. initial catalog=test;user id=root;server=localhost;logging=false;pooling=false;connect timeout=30;Database=test;Database=test;Database=test;Database=test;Database=test;Database=test;Database=test;Database=test;Database=test;Database=test;Database=test
[19 Jun 2007 8:41] Tonci Grgin
Test case:

for (int i = 0; i < 20; i++) {
    using (MySqlConnection conn = new MySqlConnection("Initial Catalog=test;User Id=root;"+
"server=localhost;Password=;Logging=false;pooling=false;Connect timeout = 30;")) 
    {
        conn.Open();
        Console.WriteLine(i+". "+conn.ConnectionString);
        conn.Close();
        conn.Dispose();
    }
}
[19 Jun 2007 17:27] 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/29127
[19 Jun 2007 17:27] 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/29127
[19 Jun 2007 17:28] Reggie Burnett
Fixed in 5.0.8 and 5.1.3
[19 Jun 2007 17:29] 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/29128
[19 Jun 2007 17:29] 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/29128
[2 Jul 2007 5:06] MC Brown
A note has been added to the 5.0.8 and 5.1.3 changelogs: 

Using the same connection string multiple times would result in Database=dbname appearing multiple times in the resulting string.