|
-
Jun 18th, 2003, 02:54 PM
#1
Thread Starter
PowerPoster
DataReader is Closed! Why?
This function call to a custom class returns a SqlDataReader but why do I get an error saying that MyReader is closed? I have verified that the reader contains data before I exit the function call. Am I doing something wrong in terms of creating a reader object to accept the return?
Code:
Dim MyReader As SqlClient.SqlDataReader = GroupManager.GetAnnouncementTypesForGroupName(strGroupName)
-
Jun 18th, 2003, 03:19 PM
#2
Fanatic Member
Whats the code in GroupManager.GetAnnouncementTypesForGroupName(strGroupName)?
-
Jun 18th, 2003, 03:23 PM
#3
Thread Starter
PowerPoster
I just figured it out. I am closing the connection in the Function so all I had to do was close the connection after I use the Reader!
lol
-
Jun 18th, 2003, 03:24 PM
#4
Thread Starter
PowerPoster
Code:
Namespace GroupManager
Public Class Groups
Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("SQLConn"))
Dim reader As SqlDataReader
Public Sub CloseConnection()
conn.Close()
End Sub
Public Function GetAnnouncementTypesForGroupName(ByVal strCookieValue As String) As SqlDataReader
Try
Dim cmd As New SqlCommand("GetAnnouncementTypesForGroupName", conn)
'add parameter
cmd.Parameters.Add("@GroupName", SqlDbType.VarChar, 50)
cmd.CommandType = CommandType.StoredProcedure
conn.Open()
'set the parameter
cmd.Parameters("@GroupName").Value = strCookieValue.ToLower
'execute the reader
reader = cmd.ExecuteReader
Return reader
Finally
End Try
End Function
etc.......
-
Jun 18th, 2003, 07:54 PM
#5
Sleep mode
As a note , this would have saved you time creating close sub !
It closes the connection right after command execution .
VB Code:
cmd.ExecuteReader(CommandBehavior.CloseConnection)
Just a thought ...
-
Jun 19th, 2003, 08:59 AM
#6
Thread Starter
PowerPoster
Originally posted by Pirate
As a note , this would have saved you time creating close sub !
It closes the connection right after command execution .
VB Code:
cmd.ExecuteReader(CommandBehavior.CloseConnection)
Just a thought ...
Never knew you could do that but in my case I need to leave it open while the reader is being used by the caller then the caller calls the close ub.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|