Im calling a module function (.vb file) which correctly returns a datareader.
If I close the connection before returnng the reader
I cant use it once returned. If I return it and it leaves the connection open I'm concerend about exceeding my available connections.
How can I close/dispose the connection
If I close the connection before returnng the reader
I cant use it once returned. If I return it and it leaves the connection open I'm concerend about exceeding my available connections.
How can I close/dispose the connection
Code:
Public Shared Function getdata(ByVal sqlin As String) As SqlDataReader
Dim sqlconn As New SqlClient.SqlConnection(System.Configuration.ConfigurationManager.AppSettings("fmsconn"))
Dim dr1 As SqlDataReader
Dim company As String = Nothing
Dim dr1cmd As New SqlCommand(sqlin, sqlconn)
If sqlconn.State = ConnectionState.Open Then sqlconn.Close()
sqlconn.Open()
dr1 = dr1cmd.ExecuteReader
Return dr1
End Function