Bug #44028 NativeDriver.Open() throws System.Exception
Submitted: 1 Apr 2009 23:06 Modified: 2 Apr 2009 15:50
Reporter: Yvan Rodrigues Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:5.2.6, 6.0.1 OS:Any
Assigned to: Reggie Burnett CPU Architecture:Any
Tags: exception, MySqlException, NativeDriver, open

[1 Apr 2009 23:06] Yvan Rodrigues
Description:
In SVN r.1434 in NativeDriver.Open() at line 199 of NativeDriver.cs, a System.Exception is thrown instead of MySqlClient.MySqlException.

This makes trapping the source of the error difficult for programmers.

How to repeat:
See snippet:

            try
            {
#if !CF
                if (Settings.ConnectionProtocol == MySqlConnectionProtocol.SharedMemory)
                {
                    SharedMemoryStream str = new SharedMemoryStream(Settings.SharedMemoryName);
                    str.Open(Settings.ConnectionTimeout);
                    baseStream = str;
                }
                else
                {
#endif
                    string pipeName = Settings.PipeName;
                    if (Settings.ConnectionProtocol != MySqlConnectionProtocol.NamedPipe)
                        pipeName = null;
                    StreamCreator sc = new StreamCreator(Settings.Server, Settings.Port, pipeName);
                    baseStream = sc.GetStream(Settings.ConnectionTimeout);
#if !CF
                }
#endif
                if (baseStream == null)
                    throw new Exception();
            }
            catch (Exception ex)
            {
                throw new MySqlException(Resources.UnableToConnectToHost, 
                    (int) MySqlErrorCode.UnableToConnectToHost, ex);
            }

Suggested fix:
Throw a MySqlException instead.
[2 Apr 2009 7:48] Tonci Grgin
Hi Yvan and thanks for spotting this.

The same code is present also in trunk, line 209. Verified as described by looking into sources.
[2 Apr 2009 15:50] 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/71219
[2 Apr 2009 15:50] Reggie Burnett
This was not really a bug but there was a couple of lines there that could safely be removed.  This changeset is about that.