473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

commandbehavior.closeconnection with applicationblocks

I am calling a shared fucntion within a class from codebehind with asp.net. The class returns a sqldatareader to be bound to a datalist. I am also utilizing ms applicationblocks. How can I return the datareader from the shared function so that the datareader is closed properly after it has been bound

th
dave
Nov 18 '05 #1
5 2659
Hi Dave,

Normally we can call the CLose method of the SQLDataReader, for example:

Dim myreader As SQLDataReader

Dim o As New MyDataClass

myreader = o.GetReader

DataList1.DataSource = myreader

DataList1.DataMember = "Name"

DataList1.DataBind()

myreader.Close()

By the way, we don't need to close the connection since it will be managed
by connection pool.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #2
Hi Dave,

Does my suggestion answer your question? Or you have other concern?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3
Your post did not answer my question

1.) I am using MS Data Application blocks to return the datareader through dr = sqlhelper.getdatreader(...)
The problem occurs because i am running this within a function and returning to the calling program the datareader. There is a property commandbehavior.closeconnection that will close the data reader after all elements have been read. How can i use commandbehavior.closeconnection if I use MS Data Application blocks

2) Your example does not align with the description of the problem. Remember that the call to the datareader is within a function and the reader is returned from the function. If i used your example and returned the reader it would not work as the reader would have been closed
th
dave
Nov 18 '05 #4
Hi Dave,

If My understanding is correct, is it "executeReader" in Data Application
blocks.

To make "ExecuteReader" work with commandbehavior.closeconnection, we need
to pass in a external Connection. Following are source code of it:

Private Overloads Shared Function ExecuteReader(ByVal connection As
SqlConnection, _
ByVal transaction
As SqlTransaction, _
ByVal commandType
As CommandType, _
ByVal commandText
As String, _
ByVal
commandParameters() As SqlParameter, _
ByVal
connectionOwnership As SqlConnectionOwnership) 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, commandParameters)

' call ExecuteReader with the appropriate CommandBehavior
If connectionOwnership = SqlConnectionOwnership.External Then
dr = cmd.ExecuteReader()
Else
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
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 SqlConnectionOwnership.External,
CommandBehavior.CloseConnection 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.)

Nov 18 '05 #5
Hi Dave,

How about my suggestion? Is it helpful or you have other concerns?

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Karuppasamy | last post by:
Hi i am using Microsoft.ApplicationBlocks.Logging building block to publish the events to the Event Log and Sql Server using the Log and Sql sinks. By default, the log message contains the...
0
by: Basem | last post by:
I have found people with similar errors using the ConfigurationManagement application block, but those solutions don't seem to do anything...basically, just trying to read in a configuration xml...
0
by: Mark | last post by:
I have a data access component that returns a SqlDataReader object. public SqlDataReader GetFeaturedArtists() { SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings)...
1
by: bootman | last post by:
Greetings, Can someone please help me with the following? I am trying to compile a C# object which contains a reference to the Microsoft.ApplicationBlocks.Data library. I have compiled the...
5
by: dave | last post by:
I am calling a shared fucntion within a class from codebehind with asp.net. The class returns a sqldatareader to be bound to a datalist. I am also utilizing ms applicationblocks. How can I return...
1
by: Oney | last post by:
I use Microsoft Exception management block to publish exception to event log. but some error occured. Error is blow, how can I solve this problem ??? Configuration Error Description: An error...
1
by: Abc | last post by:
Namespace or type 'Data' for the Imports 'Microsoft.ApplicationBlocks.Data' cannot be found. is the error which i am getting while importing Microsoft.ApplicationBlocks.Data namespace. Can...
2
by: drew.ferraro | last post by:
Hi, I am trying to build a .DLL file that uses "'Microsoft.ApplicationBlocks.ExceptionManagement.Interfaces'". I am trying to build this .DLL as fully signed. However, when I try to build, I...
0
by: mateipuiu | last post by:
When a try to run a client build on 2005, which uses the Microsoft.ApplicationBlocks.Cache.dll reference, when using a Microsoft.ApplicationBlocks.Cache.dll created on Debug mode, the client works...
1
by: linda.chen | last post by:
Hi all, I am working on a project which is created a couple years ago. It is written in C# (.net 1.1) and the developer has left the project. The auto-update feature is current not working....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.