Ich habe eine Konsolen Applikation geschrieben, um einen Account auf meinem virtuellen Server von ausserhalb zu erstellen. Dieser wird natürlich in einer DB angelegt. Mein Problem liegt jetzt darin, dass es manchmal klappt und manchmal nicht. Und ich weiss nicht woran es liegt..
Port 3306 ist offen und Fehler fallen mir auch nicht auf.
Habt ihr Tipps? Ich meine Fehler im Code können es doch nicht sein, da wie gesagt es oft so ist dass es erst 2-3 mal nicht klappt und danach auf einmal klappt. Manchmal ists aber auch so, dass es selbst nach dem 10. Mal nicht erfolgreich geht. Das ist natürlich ärgerlich...
Vorinfo: "myConnectionString" beinhaltet die Verbindungsinfos zur DB
Code:
static void Main(string[] args) { temp = args; beginningInterface(); choose(); } static public void passwordchange() { //Methode entfernt } static public void forgetpassword() { //Methode entfernt } static public void Writer() { if (access == true) { Double tempa; String login; String password; String deletekey; String email; string hashedpassword; string myInsertQuery; String question; String answer; ghi: try { Console.Clear(); Console.WriteLine(); Console.Write("Bitte Username angeben: "); login = Console.ReadLine(); password = getpw(); def: Console.Write("Bitte Löschcode (7 Zahlen) angeben: "); deletekey = Console.ReadLine(); try { tempa = Convert.ToDouble(deletekey); } catch { Console.WriteLine("Bitte 7 Zahlen lang!"); goto def; } Console.Write("Bitte Email angeben: "); email = Console.ReadLine(); Console.Write("Bitte eine Sicherheitsfrage angeben: "); question = Console.ReadLine(); Console.Write("Bitte Sicherheitsantwort geben: "); answer = Console.ReadLine(); hashedpassword = CreateMySql5Hash(password); MySqlConnection myConnection = new MySqlConnection(myConnectionString); getnum(); count = 10000 + num; myInsertQuery = "INSERT INTO account (id, login, password, social_id, email, question1, answer1) Values('" + count.ToString() + "', '" + login.ToString() + "', '" + hashedpassword.ToString() + "', '" + deletekey.ToString() + "', '" + email.ToString() + "', '" + question.ToString() + "', '" + answer.ToString() + "')"; MySqlCommand myCommand = new MySqlCommand(myInsertQuery); myCommand.Connection = myConnection; myConnection.Open(); myCommand.ExecuteNonQuery(); myCommand.Connection.Close(); Console.WriteLine("Erfolgreich angelegt!!"); Thread.Sleep(1000); } catch { Console.Clear(); Console.WriteLine("Benutzername bereits verwendet! Bitte anderen wählen"); Thread.Sleep(1000); goto ghi; } } if (access == false) { //skip Thread.Sleep(500); } Main(temp); } static public string getpw() { string temp1 = ""; string temp2 = ""; abc: Console.Write("Bitte Passwort angeben: "); ConsoleKeyInfo key; do { key = Console.ReadKey(true); if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter) { temp1 += key.KeyChar; Console.Write("*"); } else { if (key.Key == ConsoleKey.Backspace && temp1.Length > 0) { temp1 = temp1.Substring(0, (temp1.Length - 1)); Console.Write("\b \b"); } } } while (key.Key != ConsoleKey.Enter); Console.WriteLine(); Console.Write("Passwort wiederholen: "); do { key = Console.ReadKey(true); if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter) { temp2 += key.KeyChar; Console.Write("*"); } else { if (key.Key == ConsoleKey.Backspace && temp2.Length > 0) { temp2 = temp2.Substring(0, (temp2.Length - 1)); Console.Write("\b \b"); } } } while (key.Key != ConsoleKey.Enter); Console.WriteLine(); if (temp1 == temp2) { return temp1; } else { Console.WriteLine(); Console.WriteLine("##!! Passwörter nicht identisch !!##"); Console.WriteLine(); goto abc; } } static public void getnum() { try { MySqlConnection connection = new MySqlConnection(myConnectionString); MySqlCommand command = connection.CreateCommand(); command.CommandText = "SELECT * FROM account"; MySqlDataReader Reader; connection.Open(); Reader = command.ExecuteReader(); num = 0; while (Reader.Read()) { string row = ""; for (int i = 0; i < Reader.FieldCount; i++) row += Reader.GetValue(1).ToString() + ", "; num++; } connection.Close(); access = true; } catch { access = false; Console.Clear(); Console.WriteLine("Registration offline. Please contact a serveradmin."); Thread.Sleep(1000); } } static public void Reader() { Console.Clear(); string tempa; string pass = ""; Boolean access = false; Console.Write("## Warning! Important information! ##"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("ONLY FOR SERVER ADMINS!"); Console.WriteLine(); Console.Write("Login: "); tempa = Console.ReadLine(); Console.Write("password: "); ConsoleKeyInfo key; do { key = Console.ReadKey(true); if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter) { pass += key.KeyChar; Console.Write("*"); } else { if (key.Key == ConsoleKey.Backspace && pass.Length > 0) { pass = pass.Substring(0, (pass.Length - 1)); Console.Write("\b \b"); } } } while (key.Key != ConsoleKey.Enter); if (tempa == "root" && pass == "277206021a!") { access = true; Console.Clear(); } if (access == true) { try { MySqlConnection connection = new MySqlConnection(myConnectionString); MySqlCommand command = connection.CreateCommand(); command.CommandText = "SELECT * FROM account"; MySqlDataReader Reader; connection.Open(); Reader = command.ExecuteReader(); Console.WriteLine("loginname(1)\t| email(5)"); Console.WriteLine(); while (Reader.Read()) { string row = ""; row += Reader.GetValue(1).ToString() + "\t\t| "; row += Reader.GetValue(5).ToString(); Console.WriteLine(row); } connection.Close(); Console.ReadLine(); Main(temp); } catch { Console.Clear(); Console.WriteLine("Server muss Port 3306 offen haben!"); Thread.Sleep(1000); Main(temp); } } if (access == false) { Console.Clear(); Console.WriteLine("Access denied."); Thread.Sleep(1000); Main(temp); } } static public void choose() { abc: Console.WriteLine("Bitte Auswählen was Sie wollen:"); Console.WriteLine(); Console.WriteLine("1. Account Datanbank auslesen"); Console.WriteLine("2. Account anlegen"); Console.WriteLine("3. Passwort ändern"); Console.WriteLine("4. Passwort vergessen"); Console.WriteLine("5. Exit"); Console.WriteLine(); try { choice = Convert.ToInt32(Convert.ToString(Console.ReadKey().KeyChar)); } catch { Console.WriteLine("Bitte nur mögliche Auswahlmöglichekiten auswählen!"); Thread.Sleep(1500); Console.Clear(); goto abc; } if (choice == 1) { Reader(); } if (choice == 2) { Writer(); } if (choice == 3) { passwordchange(); } if (choice == 4) { forgetpassword(); } if (choice == 5) { Environment.Exit(0); } if (choice > 5) { Console.WriteLine("Bitte nur mögliche Auswahlmöglichekiten auswählen!"); Thread.Sleep(1500); Console.Clear(); goto abc; } }