title: SQL Database: 'ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.' Error message
body: <p>i'm getting this error. I've tried everything in my power to fix it. No luck sadly..</p>
  <p>The Database class:</p>
  <pre><code>internal class DatabaseDAL : IVerkoperInterface
      {
          private SqlConnection connection;
          private string conString = @&quot;Server=......;&quot;;
  
          public void OpenConnection()
          {
              try
              {
                  connection = new SqlConnection(conString);
                  connection.Open();
              }
              catch { }
          }
  
          public void CloseConnection()
          {
              try
              {
                  connection.Close();
              }
              catch { }
          }
  
          public void Create(VerkoperDataTransferObject verkoperdto)
          {
              OpenConnection();
              string query = @&quot;INSERT INTO Verkoper(ID, Naam, Woonplaats) VALUES (@id, @naam, @woonplaats)&quot;;
              SqlCommand command = new SqlCommand(query, this.connection);
              command.Parameters.AddWithValue(&quot;@id&quot;, verkoperdto.ID);
              command.Parameters.AddWithValue(&quot;@naam&quot;, verkoperdto.Naam);
              command.Parameters.AddWithValue(&quot;@woonplaats&quot;, verkoperdto.Woonplaats);
              command.ExecuteNonQuery();
              CloseConnection();
          }
  </code></pre>
  <p>The Form code:</p>
  <pre><code> internal partial class Form1 : Form
      {
          DatabaseDAL database = new DatabaseDAL();
  
          public Form1()
          {
              InitializeComponent();
              database.Create(new VerkoperDataTransferObject(&quot;Pedro&quot;, 6, 
              &quot;Tilburg&quot;));
          }
  </code></pre>
  <p>Thanks in advance!</p>
  <p>In my mind everything is logic and should work. I can't seem to understand what the problem is. C# is telling me the connection state is closed :(</p>