Just lateley on our network we are starting to get errors that have to do with open datareaders which we really do not use we use sqldataAdapters. So the following are the 2 ways we get data, but letely we are getting a lot of errors of them being open. We have never had these problems up till a month ago and nothing we have done has changed. I guess what I am asking is this the correct way to open and close our connections. We use the getdata to do all crud functions and the reader to fill all of the controls on a page.
Public Shared Function getData(ByVal sqlString As String) As DataTable
Dim cmd As New SqlCommand(sqlString, conn)
Dim ds As New DataSet
Dim da As New SqlDataAdapter
da.SelectCommand = cmd
getData = ds.Tables(0)
Public Shared Function getReader(ByVal sqlstring As String) As DataTable
Dim cmd As New SqlCommand(sqlstring, Conn)
Dim dt As New DataTable
Dim dr As SqlDataReader = Nothing
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
If dr.HasRows Then
This is a typical error we are getting.
The connection was not closed. The connection's current state is open.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationExc
eption: The connection was not closed. The connection's current state is open.
Line 39: Dim cmd As New SqlCommand(sqlstring, Conn)
Line 40: Dim dt As New DataTable
Line 41: Conn.Open()
Line 42: Dim dr As SqlDataReader = Nothing
Line 43: dr = cmd.ExecuteReader(CommandB
Source File: E:\Applications\ReadinessT
n.vb Line: 41
: The connection was not closed. The connection's current state is open.]
outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +14