Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb module function connection closing

Status
Not open for further replies.

Dashley

Programmer
Dec 5, 2002
925
0
0
US
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



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
 
faq855-7190

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top