0

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.

2
Contributors
3
Replies
17
Views
4 Years
Discussion Span
Last Post by pearl.kumar1
0

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.

0

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()
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.