title: An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll
body: <p>I am creating a connection to my database in SQL Server 2008 Management Studio edition from Visual Studio 2008.</p>
  <p>I stored a procedure called &quot;CTable&quot; in my database and I want to execute it (from Visual Studio).</p>
  <p>This is my code:</p>
  <pre><code>    Dim strConn As String
      strConn = &quot;Server=(local);Database=dbAjout;Integrated Security=True&quot;
  
      Dim MyConn As New SqlConnection(strConn)
      MyConn.Open()
      Dim cmd As SqlCommand
  
      Dim query As String = &quot;EXEC CTable&quot;
  
      cmd = New SqlCommand(query, MyConn)
  
      MyConn.Open()
      cmd.ExecuteNonQuery()
      MyConn.Close()
  End Sub
  </code></pre>
  <p>but I have this error:</p>
  <blockquote>
  <p>An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll</p>
  </blockquote>
  <p>Additional information:</p>
  <blockquote>
  <p>The connection was not closed. The connection's current state is open.</p>
  </blockquote>
  <p>What do you suggest to fix this?</p>