Why I am getting this? When I stop the server its showing many messagebox when its only…
- User
Why I am getting this? When I stop the server its showing many messagebox when its only suppost to show 1
private async void CheckGameAndExpiryAndAccountTimer_Tick(object sender, EventArgs e) { try { // Check if the game executable exists in any of the specified paths bool gameInstalled = possibleSteamPaths.Any(steamPath => File.Exists(Path.Combine(steamPath, relativeGamePath)));
// Set the label based on the game installation status if (gameInstalled) { label10.Text = "Game: Installed"; label10.ForeColor = Color.GreenYellow; // Set the color back to black } else { label10.Text = "Game: Not Installed"; label10.ForeColor = Color.Red; } // Recalculate remaining time until expiry TimeSpan remainingTime = CalculateRemainingTimeUntilExpiry(); // Display remaining time in label5 label5.Text = $"Your account will expire in {remainingTime.Days} days, {remainingTime.Hours} hours, {remainingTime.Minutes} minutes, and {remainingTime.Seconds} seconds"; // Check the account existence using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); string query = "SELECT COUNT(*) FROM accounts WHERE UserID > 0"; using (SqlCommand command = new SqlCommand(query, connection)) { int accountCount = (int)command.ExecuteScalar(); if (accountCount == 0 && !errorShown && !IsGameRunning() && isButtonClickable) { errorShown = true; MessageBox.Show("Contact hermano7066 on discord for info", "You got banned!", MessageBoxButtons.OK, MessageBoxIcon.Warning); Environment.Exit(1); // Exit the application when user clicks OK } } } } catch (SqlException ex) { if (ex.Number == -1) { // Handle the case when the server is offline if (!errorShown) // Show the error message only if it hasn't been shown before { errorShown = true; MessageBox.Show("Server is offline, or you lost connection to the ethernet\nMake sure you have a stable Wifi/Ethernet connection", "Lost Connection", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); // Exit the application when user clicks OK } } else { errorShown = true; // Handle other SQL Server exceptions Console.WriteLine(ex.Message); MessageBox.Show($"SQL Server error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception) { if (!errorShown) // Show the error message only if it hasn't been shown before { errorShown = true; // Handle other exceptions MessageBox.Show($"Something happened?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); // Exit the application when user clicks OK } }}
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - The wait operation timed out.)
- Assistant