Millkind
asked on
Sql Database connections
In VB.net I have used the Data area in the toolbar to set up a dataconnection, dataadapter and dataset to a sql database. In the code I use patronsda.Fill(Patronsds1) to fill my datasets. Does this hold a connection open? I see alot of code with conn.close and conn.open i havn't had to use any of them. Just want to make sure I'm not hurting the database.
ASKER
I'm not setting up the connection in the code, its all in the design area. All I do in the code area is patronsda.Fill(Patronsds1)
I went into the code and added
MsgBox(SqlConnection1.Stat e.ToString )
after my
patronsda.Fill(Patronsds1)
and it said the connection was closed.
So I guess it does close the connection as soon as its done
I went into the code and added
MsgBox(SqlConnection1.Stat
after my
patronsda.Fill(Patronsds1)
and it said the connection was closed.
So I guess it does close the connection as soon as its done
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I just tried the following code:
Using sqlConn As New SqlConnection("Data Source=SERVER;Initial Catalog=DATABASE;Integrate
Dim sqlCmd As New SqlCommand("SELECT * FROM Defects", sqlConn)
Dim sqlDA As New SqlDataAdapter(sqlCmd)
Dim ds As New DataSet
sqlConn.Open()
sqlDA.Fill(ds)
Console.WriteLine(sqlConn.
End Using
In the console window it shows that the connection is still Open when at that point in the code. After passing the End Using line, the connection state will be Closed, since the End Using line does the cleaning up for you. If you use the Using... End Using syntax then you won't have to worry about the connection being left open.
Hope this helps.
Jas.