diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMMCPConnection.m | 3 | ||||
-rw-r--r-- | Source/SPConnectionController.h | 2 | ||||
-rw-r--r-- | Source/SPConnectionController.m | 18 |
3 files changed, 15 insertions, 8 deletions
diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index b9bffd9b..df71ff82 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -266,6 +266,7 @@ static void forcePingTimeout(int signalNumber); thePass = NULL; if (theRet != mConnection) { [self setLastErrorMessage:nil]; + lastQueryErrorId = mysql_errno(mConnection); return mConnected = NO; } @@ -278,6 +279,7 @@ static void forcePingTimeout(int signalNumber); if (![self fetchMaxAllowedPacket]) { [self setLastErrorMessage:nil]; + lastQueryErrorId = mysql_errno(mConnection); return mConnected = NO; } @@ -688,6 +690,7 @@ static void forcePingTimeout(int signalNumber); return YES; } [self setLastErrorMessage:nil]; + lastQueryErrorId = mysql_errno(mConnection); if (connectionTunnel) { [connectionTunnel disconnect]; [delegate setTitlebarStatus:@"SSH Disconnected"]; diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h index ad61cfa8..03245d26 100644 --- a/Source/SPConnectionController.h +++ b/Source/SPConnectionController.h @@ -111,7 +111,7 @@ enum spconnection_types - (void)initiateSSHTunnelConnection; - (void)sshTunnelCallback:(SPSSHTunnel *)theTunnel; - (void)initiateMySQLConnection; -- (void)failConnectionWithErrorMessage:(NSString *)theErrorMessage withDetail:(NSString *)errorDetail; +- (void)failConnectionWithTitle:(NSString *)theTitle errorMessage:(NSString *)theErrorMessage detail:(NSString *)errorDetail; - (void)errorSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(NSString *)contextInfo; - (void) addConnectionToDocument; diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index 97ad5983..71f075c1 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -236,7 +236,7 @@ if (newState == SPSSH_STATE_IDLE) { [tableDocument setTitlebarStatus:@"SSH Disconnected"]; - [self failConnectionWithErrorMessage:[theTunnel lastError] withDetail:[sshTunnel debugMessages]]; + [self failConnectionWithTitle:NSLocalizedString(@"SSH connection failed!", @"SSH connection failed title") errorMessage:[theTunnel lastError] detail:[sshTunnel debugMessages]]; } else if (newState == SPSSH_STATE_CONNECTED) { [tableDocument setTitlebarStatus:@"SSH Connected"]; [self initiateMySQLConnection]; @@ -304,12 +304,16 @@ } if (![mySQLConnection isConnected]) { - NSString *errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@, or the request timed out.\n\nBe sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently %i seconds).\n\nMySQL said: %@", @"message of panel when connection to host failed"), [self host], [[prefs objectForKey:@"ConnectionTimeoutValue"] intValue], [mySQLConnection getLastErrorMessage]]; + NSString *errorMessage; if (sshTunnel && [sshTunnel state] == SPSSH_STATE_FORWARDING_FAILED) { errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@ because the port connection via SSH was refused.\n\nPlease ensure that your MySQL host is set up to allow TCP/IP connections (no --skip-networking) and is configured to allow connections from the host you are tunnelling via.\n\nYou may also want to check the port is correct and that you have the necessary privileges.\n\nChecking the error detail will show the SSH debug log which may provide more details.\n\nMySQL said: %@", @"message of panel when SSH port forwarding failed"), [self host], [mySQLConnection getLastErrorMessage]]; - [self failConnectionWithErrorMessage:errorMessage withDetail:[sshTunnel debugMessages]]; + [self failConnectionWithTitle:NSLocalizedString(@"SSH port forwarding failed", @"title when ssh tunnel port forwarding failed") errorMessage:errorMessage detail:[sshTunnel debugMessages]]; + } else if ([mySQLConnection getLastErrorID] == 1045) { // "Access denied" error + errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@ because access was denied.\n\nDouble-check your username and password and ensure that access from your current location is permitted.\n\nMySQL said: %@", @"message of panel when connection to host failed due to access denied error"), [self host], [mySQLConnection getLastErrorMessage]]; + [self failConnectionWithTitle:NSLocalizedString(@"Access denied!", @"connection failed due to access denied title") errorMessage:errorMessage detail:nil]; } else { - [self failConnectionWithErrorMessage:errorMessage withDetail:nil]; + errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@, or the request timed out.\n\nBe sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently %i seconds).\n\nMySQL said: %@", @"message of panel when connection to host failed"), [self host], [[prefs objectForKey:@"ConnectionTimeoutValue"] intValue], [mySQLConnection getLastErrorMessage]]; + [self failConnectionWithTitle:NSLocalizedString(@"Connection failed!", @"connection failed title") errorMessage:errorMessage detail:nil]; } if (sshTunnel) [sshTunnel release], sshTunnel = nil; @@ -319,7 +323,7 @@ } if (![[self database] isEqualToString:@""]) { if (![mySQLConnection selectDB:[self database]]) { - [self failConnectionWithErrorMessage:[NSString stringWithFormat:NSLocalizedString(@"Connected to host, but unable to connect to database %@.\n\nBe sure that the database exists and that you have the necessary privileges.\n\nMySQL said: %@", @"message of panel when connection to db failed"), [self database], [mySQLConnection getLastErrorMessage]] withDetail:nil]; + [self failConnectionWithTitle:NSLocalizedString(@"Could not select database", @"message when database selection failed") errorMessage:[NSString stringWithFormat:NSLocalizedString(@"Connected to host, but unable to connect to database %@.\n\nBe sure that the database exists and that you have the necessary privileges.\n\nMySQL said: %@", @"message of panel when connection to db failed"), [self database], [mySQLConnection getLastErrorMessage]] detail:nil]; if (sshTunnel) [sshTunnel release], sshTunnel = nil; [mySQLConnection release], mySQLConnection = nil; return; @@ -343,7 +347,7 @@ * Ends a connection attempt by stopping the connection animation and * displaying a specified error message. */ -- (void)failConnectionWithErrorMessage:(NSString *)theErrorMessage withDetail:(NSString *)errorDetail +- (void)failConnectionWithTitle:(NSString *)theTitle errorMessage:(NSString *)theErrorMessage detail:(NSString *)errorDetail { // Clean up the interface [progressIndicator stopAnimation:self]; @@ -360,7 +364,7 @@ if (errorDetail) [errorDetailText setString:errorDetail]; // Display the connection error message - NSBeginAlertSheet(NSLocalizedString(@"Connection failed!", @"connection failed title"), NSLocalizedString(@"OK", @"OK button"), errorDetail?NSLocalizedString(@"Show detail", @"Show detail button"):nil, nil, documentWindow, self, nil, @selector(errorSheetDidEnd:returnCode:contextInfo:), @"connect", theErrorMessage); + NSBeginAlertSheet(theTitle, NSLocalizedString(@"OK", @"OK button"), errorDetail?NSLocalizedString(@"Show detail", @"Show detail button"):nil, nil, documentWindow, self, nil, @selector(errorSheetDidEnd:returnCode:contextInfo:), @"connect", theErrorMessage); } |