From: Date: January 11 2007 9:18pm Subject: Connector/NET commit: r548 - in branches/1.0: . TestSuite mysqlclient List-Archive: http://lists.mysql.com/commits/17990 X-Bug: 24802 Message-Id: <200701112018.l0BKIJPT012148@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/1.0/CHANGES branches/1.0/TestSuite/ConnectionTests.cs branches/1.0/mysqlclient/Exception.cs branches/1.0/mysqlclient/MySqlError.cs branches/1.0/mysqlclient/Resources.Designer.cs branches/1.0/mysqlclient/Resources.resx branches/1.0/mysqlclient/nativedriver.cs Log: Bug #24802 Error Handling Fixed this by making sure the Number proper of MySqlException is set when we can't connect to the given host Modified: branches/1.0/CHANGES =================================================================== --- branches/1.0/CHANGES 2007-01-11 20:12:52 UTC (rev 547) +++ branches/1.0/CHANGES 2007-01-11 20:18:19 UTC (rev 548) @@ -18,6 +18,7 @@ Bug #25013 Return Value parameter not found Bug #22400 Nested transactions Bug #25443 ExecuteScalar() hangs when more than one bad result + Bug #24802 Error Handling Other changes ------------- Modified: branches/1.0/TestSuite/ConnectionTests.cs =================================================================== --- branches/1.0/TestSuite/ConnectionTests.cs 2007-01-11 20:12:52 UTC (rev 547) +++ branches/1.0/TestSuite/ConnectionTests.cs 2007-01-11 20:18:19 UTC (rev 548) @@ -330,5 +330,28 @@ } suExecSQL("DELETE FROM mysql.user WHERE user='quotedUser'"); } + + /// + /// Bug #24802 Error Handling + /// + [Test] + public void TestConnectingSocketBadHostName() + { + string connStr = "server=foobar;user id=foouser;password=;database=Test;" + + "pooling=false"; + MySqlConnection c = new MySqlConnection(connStr); + try + { + c.Open(); + } + catch (MySqlException ex) + { + Assert.AreEqual((int)MySqlErrorCode.UnableToConnectToHost, ex.Number); + } + catch (Exception e) + { + Assert.Fail(e.Message); + } + } } } Modified: branches/1.0/mysqlclient/Exception.cs =================================================================== --- branches/1.0/mysqlclient/Exception.cs 2007-01-11 20:12:52 UTC (rev 547) +++ branches/1.0/mysqlclient/Exception.cs 2007-01-11 20:18:19 UTC (rev 548) @@ -53,6 +53,12 @@ this.isFatal = isFatal; } + internal MySqlException(string msg, int errno, Exception inner) + : this(msg, inner) + { + errorCode = errno; + } + internal MySqlException(string msg, int errno) : this(msg) { Modified: branches/1.0/mysqlclient/MySqlError.cs =================================================================== --- branches/1.0/mysqlclient/MySqlError.cs 2007-01-11 20:12:52 UTC (rev 547) +++ branches/1.0/mysqlclient/MySqlError.cs 2007-01-11 20:18:19 UTC (rev 548) @@ -113,35 +113,38 @@ /// The specified key was not found. /// KeyNotFound = 1032, - /* ER_NOT_FORM_FILE 1033 - ER_NOT_KEYFILE 1034 - ER_OLD_KEYFILE 1035 - ER_OPEN_AS_READONLY 1036 - ER_OUTOFMEMORY 1037 - ER_OUT_OF_SORTMEMORY 1038 - ER_UNEXPECTED_EOF 1039 - ER_CON_COUNT_ERROR 1040 - ER_OUT_OF_RESOURCES 1041 - ER_BAD_HOST_ERROR 1042 - ER_HANDSHAKE_ERROR 1043 - ER_DBACCESS_DENIED_ERROR 1044 - ER_ACCESS_DENIED_ERROR 1045 - ER_NO_DB_ERROR 1046 - ER_UNKNOWN_COM_ERROR 1047 - ER_BAD_NULL_ERROR 1048 - ER_BAD_DB_ERROR 1049 - ER_TABLE_EXISTS_ERROR 1050 - ER_BAD_TABLE_ERROR 1051 - ER_NON_UNIQ_ERROR 1052 - ER_SERVER_SHUTDOWN 1053 - ER_BAD_FIELD_ERROR 1054 - ER_WRONG_FIELD_WITH_GROUP 1055 - ER_WRONG_GROUP_FIELD 1056 - ER_WRONG_SUM_SELECT 1057 - ER_WRONG_VALUE_COUNT 1058 - ER_TOO_LONG_IDENT 1059 - ER_DUP_FIELDNAME 1060*/ - /// + /* ER_NOT_FORM_FILE 1033 + ER_NOT_KEYFILE 1034 + ER_OLD_KEYFILE 1035 + ER_OPEN_AS_READONLY 1036 + ER_OUTOFMEMORY 1037 + ER_OUT_OF_SORTMEMORY 1038 + ER_UNEXPECTED_EOF 1039 + ER_CON_COUNT_ERROR 1040 + ER_OUT_OF_RESOURCES 1041 */ + /// + /// Given when the connection is unable to successfully connect to host. + /// + UnableToConnectToHost = 1042, +/* ER_HANDSHAKE_ERROR 1043 + ER_DBACCESS_DENIED_ERROR 1044 + ER_ACCESS_DENIED_ERROR 1045 + ER_NO_DB_ERROR 1046 + ER_UNKNOWN_COM_ERROR 1047 + ER_BAD_NULL_ERROR 1048 + ER_BAD_DB_ERROR 1049 + ER_TABLE_EXISTS_ERROR 1050 + ER_BAD_TABLE_ERROR 1051 + ER_NON_UNIQ_ERROR 1052 + ER_SERVER_SHUTDOWN 1053 + ER_BAD_FIELD_ERROR 1054 + ER_WRONG_FIELD_WITH_GROUP 1055 + ER_WRONG_GROUP_FIELD 1056 + ER_WRONG_SUM_SELECT 1057 + ER_WRONG_VALUE_COUNT 1058 + ER_TOO_LONG_IDENT 1059 + ER_DUP_FIELDNAME 1060*/ + /// /// Duplicate Key Name /// DuplicateKeyName = 1061, Modified: branches/1.0/mysqlclient/Resources.Designer.cs =================================================================== --- branches/1.0/mysqlclient/Resources.Designer.cs 2007-01-11 20:12:52 UTC (rev 547) +++ branches/1.0/mysqlclient/Resources.Designer.cs 2007-01-11 20:18:19 UTC (rev 548) @@ -394,7 +394,15 @@ return ResourceManager.GetString("StreamNoWrite", resourceCulture); } } - + + internal static string UnableToConnectToHost + { + get + { + return ResourceManager.GetString("UnableToConnectToHost", resourceCulture); + } + } + /// /// Looks up a localized string similar to Unable to execute stored procedure '{0}'.. /// Modified: branches/1.0/mysqlclient/Resources.resx =================================================================== --- branches/1.0/mysqlclient/Resources.resx 2007-01-11 20:12:52 UTC (rev 547) +++ branches/1.0/mysqlclient/Resources.resx 2007-01-11 20:18:19 UTC (rev 548) @@ -246,4 +246,7 @@ A return value parameter already exists in the parameter collection. + + Unable to connect to any of the specified MySQL hosts. + \ No newline at end of file Modified: branches/1.0/mysqlclient/nativedriver.cs =================================================================== --- branches/1.0/mysqlclient/nativedriver.cs 2007-01-11 20:12:52 UTC (rev 547) +++ branches/1.0/mysqlclient/nativedriver.cs 2007-01-11 20:18:19 UTC (rev 548) @@ -156,10 +156,15 @@ StreamCreator sc = new StreamCreator(Settings.Server, Settings.Port, pipeName); stream = sc.GetStream((uint)Settings.ConnectionTimeout); } + if (stream == null) + throw new Exception(); } catch (Exception ex) { - throw new MySqlException("Unable to connect to any of the specified MySQL hosts", ex); + throw new MySqlException( + Resources.UnableToConnectToHost, + (int)MySqlErrorCode.UnableToConnectToHost, + ex); }