Bug #39728 MySqlConnectionStringBuilder GetConnectionString(true) returns null unexpectedly
Submitted: 29 Sep 2008 11:53 Modified: 10 Oct 2008 12:27
Reporter: Christopher Jerdonek Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:5.2.3.0 OS:Windows
Assigned to: CPU Architecture:Any
Tags: connection string, connector, includepass

[29 Sep 2008 11:53] Christopher Jerdonek
Description:
MySqlConnectionStringBuilder's GetConnectionString method returns null when passing true for the "includePass" parameter after initializing the ConnectionString property via DbConnectionStringBuilder's public setter.

How to repeat:
MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();

builder.ConnectionString = "server=test1;pwd=test2";

// The connectionString value below is null, but one would 
// expect it to return "server=test1;pwd=test2".
string connectionString = builder.GetConnectionString(true);

// Indeed, the connectionString value below is "server=test1"
// as expected.
connectionString = builder.GetConnectionString(false);
[29 Sep 2008 14:03] Tonci Grgin
Hi Christopher and thanks for your report.

Verified as described...

    MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
    builder.ConnectionString = "server=test1;pwd=test2";
    //played with uid=root;Persist Security Info=true; to no avail
    string connectionString = builder.GetConnectionString(false);
    Console.WriteLine(connectionString);
    Assert.AreEqual("server=test1", connectionString);
    connectionString = builder.GetConnectionString(true);
    Console.WriteLine(connectionString);
    Assert.AreEqual("server=test1;pwd=test2", connectionString);

It appears that MySQLConnectionStringBuilder.cs, line 1021 shows null for originalConnectionString although it is called with proper value...

        public string GetConnectionString(bool includePass)
        {
            if (includePass)
                return originalConnectionString;
            string connStr = persistConnString.ToString();
            return connStr.Remove(connStr.Length - 1, 1);
        }
[8 Oct 2008 17:46] 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/55797
[8 Oct 2008 17:47] Reggie Burnett
fixed by making MySqlConnectionStringBuilder.GetConnectionString an internal method.  It should not have been publicly available anyway.  It is used internally by the MySqlConnection.ConnectionString property
[10 Oct 2008 12:27] Tony Bedford
An entry was added to the 5.2.4 changelog:

After the ConnectionString property was initialized via the public setter of DbConnectionStringBuilder, the GetConnectionString method of MySqlConnectionStringBuilder incorrectly returned null when true was assigned to the includePass parameter.