title: C# System.InvalidOperationException error
body: <p>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.</p>
  <blockquote>
  <p>System.InvalidOperationException Connection must be valid and open.</p>
  </blockquote>
  <p>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:</p>
  <pre><code>string verbindungsdaten = &quot;SERVER = localhost;&quot; +
                            &quot;DATABASE = db;&quot; +
                            &quot;UID = Sarper;&quot; +
                            &quot;PASSWORD = Bmw03082009;&quot;;
  
  MySqlConnection verbindung = new MySqlConnection(verbindungsdaten);
  
  Random meinrandom = new Random();
  int zahl = meinrandom.Next(100000, 1000000);
  Console.WriteLine(&quot;Ihr Passwort ist zwischen den Werten: 100000 - 1000000&quot;);
  Console.Write(&quot;Geben sie bitte die Benutzung vom Passwort damit sie es 
  wiederverwenden können ein: &quot;);
  string benutzung1 = Console.ReadLine();
  Console.WriteLine(&quot;Ihr Passwort wurde generiert: &quot; + zahl);
  Console.WriteLine(&quot;Alle Daten im überblick mit Benutzung: &quot;);
  
  string command = &quot;INSERT INTO passwörter VALUES ('&quot; + benutzung1 + &quot;', '&quot; + zahl + &quot;');&quot;;
  
  MySqlCommand ausführen = new MySqlCommand(command);
  ausführen.Connection = verbindung;
  
  string com = &quot;SELECT * FROM passwörter;&quot;;
  MySqlCommand com11 = new MySqlCommand(com);
  
  verbindung.Open();
  ausführen.ExecuteNonQuery();
  MySqlDataReader Reader;
      
  Reader = com11.ExecuteReader();
  Reader.Read();
  Console.WriteLine(&quot;Benutzung &quot; + Reader.GetValue(0).ToString());
  Console.WriteLine(&quot;Passwort &quot; + Reader.GetValue(1).ToString());
  verbindung.Close();
  </code></pre>
  <p>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</p>