HI,
IF i run my VB.NET Application.
IT shows"Unhandled exception has occured.Connection was not closed.The Connection's current state is open".

Kindly Suggest How to Solve this Problem.

Recommended Answers

All 3 Replies

You are trying to Open a connection that is already open (most likely). We can help if you show the relevant part of your code.

Hi,
The code is,

    con.Open()
        cmd = New SqlCommand("SELECT COUNT(*)AS COUNTS FROM TABLE_NAME", con)
        cmd.ExecuteNonQuery()
        da = New SqlDataAdapter
        dr = cmd.ExecuteReader
        While dr.Read
            EMP_cnt = dr("counts")
        End While
        con.Close()
        EMP_id = "RD" & EMP_cnt 
        con.Open()
        cmd = New SqlCommand("INSERT INTO TABLE_NAME VALUES('" & EMP_id & "','" + CMBVALUE.TEXT.Text + "',0)", con)
        cmd.ExecuteNonQuery()
        con.Close()
        MsgBox("Detail Added", MsgBoxStyle.Information)
        Call clear_EMP()

The error is:
577952770739b443c60f1390e93991e4

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.