I'm getting the following error: ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.

Yet, in my code, the connection state is opened right before this exception is thrown. I don't understand why it says it would be closed??

Code:

```
Try

conn = New SqlConnection(connectionString)

If i = objId.Count - 1 Then
    cmd = New SqlCommand("Update DmdOD SET note = @note, note1 = @note1, noteBranch = @branch, noteAccountNo = @account," & _
    "noteType = @type, noteSub = @sub, lastUpdatedBy = @user  WHERE no = @no and id=@id", conn)
                        cmd.Parameters.Add(New SqlParameter("@id", objId.Item(i)))
End If

cmd.Parameters.Add(New SqlParameter("@note", ddl.SelectedItem.Text))

If ddlNote.SelectedItem.Text IsNot "" Then
   cmd.Parameters.Add(New SqlParameter("@note1", ddlNote.SelectedItem.Text))
Else
   cmd.Parameters.Add(New SqlParameter("@note1", DBNull.Value))
End If

If txtAccountBox.Text IsNot "" Then
   cmd.Parameters.Add(New SqlParameter("@account", txtAccountBox.Text))
Else
   cmd.Parameters.Add(New SqlParameter("@account", DBNull.Value))
End If

If txtSubBox.Text IsNot "" Then
   cmd.Parameters.Add(New SqlParameter("@sub", txtSubBox.Text))
Else
   cmd.Parameters.Add(New SqlParameter("@sub", DBNull.Value))
End If

cmd.Parameters.Add(New SqlParameter("@no", row.Cells(1).Text))

cmd.Parameters.Add(New SqlParameter("@user", HttpContext.Current.User.Identity.Name.ToString()))

If ddBranchBox.SelectedItem.Text IsNot "" Then
   cmd.Parameters.Add(New SqlParameter("@branch", ddBranchBox.SelectedItem.Text))
Else
   cmd.Parameters.Add(New SqlParameter("@branch", DBNull.Value))
End If

If ddTypeBox.SelectedItem.Text IsNot "" Then
   cmd.Parameters.Add(New SqlParameter("@type", ddTypeBox.SelectedItem.Text))
Else
   cmd.Parameters.Add(New SqlParameter("@type", DBNull.Value))
End If

conn.Open()
   cmd.ExecuteNonQuery() ' Where the exception is being thrown
conn.Close()

   cmd.Parameters.Clear()

   LblErr.ForeColor = Drawing.Color.Green
   LblErr.Text = "Data Saved!"

Catch ex As Exception
   LblErr.ForeColor = Drawing.Color.DarkRed
   LblErr.Text = "Save Button - " & ex.Message
Finally
   conn.Dispose()
End Try

```