Hi Dave,
If My understanding is correct, is it "executeRea der" in Data Application
blocks.
To make "ExecuteRea der" work with commandbehavior .closeconnectio n, we need
to pass in a external Connection. Following are source code of it:
Private Overloads Shared Function ExecuteReader(B yVal connection As
SqlConnection, _
ByVal transaction
As SqlTransaction, _
ByVal commandType
As CommandType, _
ByVal commandText
As String, _
ByVal
commandParamete rs() As SqlParameter, _
ByVal
connectionOwner ship As SqlConnectionOw nership) As SqlDataReader
'create a command and prepare it for execution
Dim cmd As New SqlCommand()
'create a reader
Dim dr As SqlDataReader
PrepareCommand( cmd, connection, transaction, commandType,
commandText, commandParamete rs)
' call ExecuteReader with the appropriate CommandBehavior
If connectionOwner ship = SqlConnectionOw nership.Externa l Then
dr = cmd.ExecuteRead er()
Else
dr = cmd.ExecuteRead er(CommandBehav ior.CloseConnec tion)
End If
'detach the SqlParameters from the command object, so they can
be used again
cmd.Parameters. Clear()
Return dr
End Function 'ExecuteReader
As you see when last parameter is SqlConnectionOw nership.Externa l,
CommandBehavior .CloseConnectio n will be used. Is this helpful in your
project?
Luke
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)