I wanted to make a password generator and it should save the password for what you want to use the password then I wanted that the program displays all the datas in my database. so, I can look at it. Also, I am using Console Application(.NET Framwork).When I used the program without displaying the data, it worked. But, when I put my displaying code, it makes that error.
System.InvalidOperationException Connection must be valid and open.
I don't know how to fix that. It would be super cool, if you guys can help me and make me more smart :D Here is the program code:
string verbindungsdaten = "SERVER = localhost;" +
"DATABASE = db;" +
"UID = Sarper;" +
"PASSWORD = Bmw03082009;";
MySqlConnection verbindung = new MySqlConnection(verbindungsdaten);
Random meinrandom = new Random();
int zahl = meinrandom.Next(100000, 1000000);
Console.WriteLine("Ihr Passwort ist zwischen den Werten: 100000 - 1000000");
Console.Write("Geben sie bitte die Benutzung vom Passwort damit sie es
wiederverwenden können ein: ");
string benutzung1 = Console.ReadLine();
Console.WriteLine("Ihr Passwort wurde generiert: " + zahl);
Console.WriteLine("Alle Daten im überblick mit Benutzung: ");
string command = "INSERT INTO passwörter VALUES ('" + benutzung1 + "', '" + zahl + "');";
MySqlCommand ausführen = new MySqlCommand(command);
ausführen.Connection = verbindung;
string com = "SELECT * FROM passwörter;";
MySqlCommand com11 = new MySqlCommand(com);
verbindung.Open();
ausführen.ExecuteNonQuery();
MySqlDataReader Reader;
Reader = com11.ExecuteReader();
Reader.Read();
Console.WriteLine("Benutzung " + Reader.GetValue(0).ToString());
Console.WriteLine("Passwort " + Reader.GetValue(1).ToString());
verbindung.Close();
It is german again because I am from Germany.That are only things in the WriteLine codes, but I think you can unserstand it. :D