PC Review


Reply
Thread Tools Rate Thread

commandbehavior.CloseConnection quick question

 
 
=?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=
Guest
Posts: n/a
 
      3rd Aug 2005
does the cmd.ExecuteScalar() auto close the connection the same as
RxecuteReader(commandbehavior.CloseConnection)?

--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes
 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      3rd Aug 2005
It does not have such an overload. You have to close the connection
manually.

"WebBuilder451" <(E-Mail Removed)> wrote in message
news:3D41865C-680D-4A70-9999-(E-Mail Removed)...
> does the cmd.ExecuteScalar() auto close the connection the same as
> RxecuteReader(commandbehavior.CloseConnection)?
>
> --
> thanks (as always)
> some day i''m gona pay this forum back for all the help i''m getting
> kes



 
Reply With Quote
 
Sahil Malik [MVP]
Guest
Posts: n/a
 
      3rd Aug 2005
No it doesn't.

--

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
-------------------------------------------------------------------------------------------

"WebBuilder451" <(E-Mail Removed)> wrote in message
news:3D41865C-680D-4A70-9999-(E-Mail Removed)...
> does the cmd.ExecuteScalar() auto close the connection the same as
> RxecuteReader(commandbehavior.CloseConnection)?
>
> --
> thanks (as always)
> some day i''m gona pay this forum back for all the help i''m getting
> kes



 
Reply With Quote
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      3rd Aug 2005
No it doesn't and it SHOULD (IMHO).


--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"Sahil Malik [MVP]" <(E-Mail Removed)> wrote in message
news:e$(E-Mail Removed)...
> No it doesn't.
>
> --
>
> - Sahil Malik [MVP]
> ADO.NET 2.0 book -
> http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
> -------------------------------------------------------------------------------------------
>
> "WebBuilder451" <(E-Mail Removed)> wrote in message
> news:3D41865C-680D-4A70-9999-(E-Mail Removed)...
>> does the cmd.ExecuteScalar() auto close the connection the same as
>> RxecuteReader(commandbehavior.CloseConnection)?
>>
>> --
>> thanks (as always)
>> some day i''m gona pay this forum back for all the help i''m getting
>> kes

>
>



 
Reply With Quote
 
=?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=
Guest
Posts: n/a
 
      3rd Aug 2005
it does seem strange that it's not available.
thanks for your reply!
--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes


"William (Bill) Vaughn" wrote:

> No it doesn't and it SHOULD (IMHO).
>
>
> --
> ____________________________________
> William (Bill) Vaughn
> Author, Mentor, Consultant
> Microsoft MVP
> www.betav.com/blog/billva
> www.betav.com
> Please reply only to the newsgroup so that others can benefit.
> This posting is provided "AS IS" with no warranties, and confers no rights.
> __________________________________
>
> "Sahil Malik [MVP]" <(E-Mail Removed)> wrote in message
> news:e$(E-Mail Removed)...
> > No it doesn't.
> >
> > --
> >
> > - Sahil Malik [MVP]
> > ADO.NET 2.0 book -
> > http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
> > -------------------------------------------------------------------------------------------
> >
> > "WebBuilder451" <(E-Mail Removed)> wrote in message
> > news:3D41865C-680D-4A70-9999-(E-Mail Removed)...
> >> does the cmd.ExecuteScalar() auto close the connection the same as
> >> RxecuteReader(commandbehavior.CloseConnection)?
> >>
> >> --
> >> thanks (as always)
> >> some day i''m gona pay this forum back for all the help i''m getting
> >> kes

> >
> >

>
>
>

 
Reply With Quote
 
Sahil Malik [MVP]
Guest
Posts: n/a
 
      4th Aug 2005
Why "it should"?

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
----------------------------------------------------------------------------

"William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> No it doesn't and it SHOULD (IMHO).
>
>
> --
> ____________________________________
> William (Bill) Vaughn
> Author, Mentor, Consultant
> Microsoft MVP
> www.betav.com/blog/billva
> www.betav.com
> Please reply only to the newsgroup so that others can benefit.
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> __________________________________
>
> "Sahil Malik [MVP]" <(E-Mail Removed)> wrote in message
> news:e$(E-Mail Removed)...
>> No it doesn't.
>>
>> --
>>
>> - Sahil Malik [MVP]
>> ADO.NET 2.0 book -
>> http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
>> -------------------------------------------------------------------------------------------
>>
>> "WebBuilder451" <(E-Mail Removed)> wrote in
>> message news:3D41865C-680D-4A70-9999-(E-Mail Removed)...
>>> does the cmd.ExecuteScalar() auto close the connection the same as
>>> RxecuteReader(commandbehavior.CloseConnection)?
>>>
>>> --
>>> thanks (as always)
>>> some day i''m gona pay this forum back for all the help i''m getting
>>> kes

>>
>>

>
>



 
Reply With Quote
 
=?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=
Guest
Posts: n/a
 
      4th Aug 2005
there's a lot i don't know concerning ado.net, so please show me how to do
this.
why is there one for a datareader
i'm returning datareaders via functions and the
commandbehavior.closeconnection
means i can use RETURN cmd.executereader(commandbehavior.closeconnection)
i can't do the same with executescaler. I'm setting a variable, closing the
connection and returning the variable.
thanks
kes
--
thanks (as always)
some day i''m gona pay this forum back for all the help i''m getting
kes


"Sahil Malik [MVP]" wrote:

> Why "it should"?
>
> - Sahil Malik [MVP]
> ADO.NET 2.0 book -
> http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
> ----------------------------------------------------------------------------
>
> "William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > No it doesn't and it SHOULD (IMHO).
> >
> >
> > --
> > ____________________________________
> > William (Bill) Vaughn
> > Author, Mentor, Consultant
> > Microsoft MVP
> > www.betav.com/blog/billva
> > www.betav.com
> > Please reply only to the newsgroup so that others can benefit.
> > This posting is provided "AS IS" with no warranties, and confers no
> > rights.
> > __________________________________
> >
> > "Sahil Malik [MVP]" <(E-Mail Removed)> wrote in message
> > news:e$(E-Mail Removed)...
> >> No it doesn't.
> >>
> >> --
> >>
> >> - Sahil Malik [MVP]
> >> ADO.NET 2.0 book -
> >> http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
> >> -------------------------------------------------------------------------------------------
> >>
> >> "WebBuilder451" <(E-Mail Removed)> wrote in
> >> message news:3D41865C-680D-4A70-9999-(E-Mail Removed)...
> >>> does the cmd.ExecuteScalar() auto close the connection the same as
> >>> RxecuteReader(commandbehavior.CloseConnection)?
> >>>
> >>> --
> >>> thanks (as always)
> >>> some day i''m gona pay this forum back for all the help i''m getting
> >>> kes
> >>
> >>

> >
> >

>
>
>

 
Reply With Quote
 
Sahil Malik [MVP]
Guest
Posts: n/a
 
      4th Aug 2005
Kes,

Here is a very common scenario where you DON"T want the connection to close
(even the logical connection, not the pooled physical connection).

Say you have a hierarchical dataset taht you are trying to save. DataAdapter
cannot do that job for you, you have to resort to your commands. In that
circumstance, you want a number of Command.ExecuteScalar, or NonQuery to
execute, and stay on the same transaction.

In that circumstance it makes sense that the connection not be closed,
because you need to stick with the same underlying physical connection (so
you can keep a hold of it).

Secondly, all Command.Execute* expect an open connection. Why should
ExecuteScalar be non-standard?

Now if you'd argue that there should be a non default overload that accepts
a parameter, that makes it work like a DataAdapter.Fill operation - I can
probably agree to that, but you can easily emulate that in your Data Layer
anyway.

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
----------------------------------------------------------------------------


"WebBuilder451" <(E-Mail Removed)> wrote in message
news:21611E5F-3F58-43C7-B27C-(E-Mail Removed)...
> there's a lot i don't know concerning ado.net, so please show me how to do
> this.
> why is there one for a datareader
> i'm returning datareaders via functions and the
> commandbehavior.closeconnection
> means i can use RETURN cmd.executereader(commandbehavior.closeconnection)
> i can't do the same with executescaler. I'm setting a variable, closing
> the
> connection and returning the variable.
> thanks
> kes
> --
> thanks (as always)
> some day i''m gona pay this forum back for all the help i''m getting
> kes
>
>
> "Sahil Malik [MVP]" wrote:
>
>> Why "it should"?
>>
>> - Sahil Malik [MVP]
>> ADO.NET 2.0 book -
>> http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
>> ----------------------------------------------------------------------------
>>
>> "William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > No it doesn't and it SHOULD (IMHO).
>> >
>> >
>> > --
>> > ____________________________________
>> > William (Bill) Vaughn
>> > Author, Mentor, Consultant
>> > Microsoft MVP
>> > www.betav.com/blog/billva
>> > www.betav.com
>> > Please reply only to the newsgroup so that others can benefit.
>> > This posting is provided "AS IS" with no warranties, and confers no
>> > rights.
>> > __________________________________
>> >
>> > "Sahil Malik [MVP]" <(E-Mail Removed)> wrote in message
>> > news:e$(E-Mail Removed)...
>> >> No it doesn't.
>> >>
>> >> --
>> >>
>> >> - Sahil Malik [MVP]
>> >> ADO.NET 2.0 book -
>> >> http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
>> >> -------------------------------------------------------------------------------------------
>> >>
>> >> "WebBuilder451" <(E-Mail Removed)> wrote in
>> >> message news:3D41865C-680D-4A70-9999-(E-Mail Removed)...
>> >>> does the cmd.ExecuteScalar() auto close the connection the same as
>> >>> RxecuteReader(commandbehavior.CloseConnection)?
>> >>>
>> >>> --
>> >>> thanks (as always)
>> >>> some day i''m gona pay this forum back for all the help i''m getting
>> >>> kes
>> >>
>> >>
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      4th Aug 2005
I am also curious. Why it should?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

"William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> No it doesn't and it SHOULD (IMHO).
>
>
> --
> ____________________________________
> William (Bill) Vaughn
> Author, Mentor, Consultant
> Microsoft MVP
> www.betav.com/blog/billva
> www.betav.com
> Please reply only to the newsgroup so that others can benefit.
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
> __________________________________
>
> "Sahil Malik [MVP]" <(E-Mail Removed)> wrote in message
> news:e$(E-Mail Removed)...
>> No it doesn't.
>>
>> --
>>
>> - Sahil Malik [MVP]
>> ADO.NET 2.0 book -
>> http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
>> -------------------------------------------------------------------------------------------
>>
>> "WebBuilder451" <(E-Mail Removed)> wrote in
>> message news:3D41865C-680D-4A70-9999-(E-Mail Removed)...
>>> does the cmd.ExecuteScalar() auto close the connection the same as
>>> RxecuteReader(commandbehavior.CloseConnection)?
>>>
>>> --
>>> thanks (as always)
>>> some day i''m gona pay this forum back for all the help i''m getting
>>> kes

>>
>>

>
>



 
Reply With Quote
 
William \(Bill\) Vaughn
Guest
Posts: n/a
 
      4th Aug 2005
Oh, I can't think of more than these reasons:
1) Connections are a precious resource. Getting them closed quickly
(when they can be) is good for scalability
2) Consistency. All of the Command execute functions that require open
connections should have a CommandBehavior.CloseConnection available.
3) Too many folks complain about overflowing connection pools look to
the ExecuteReader as the cause--it could be elsewhere. Setting CBCC makes it
easier to manage connections.

Just because the enumeration is there does not mean you have to set it.
There are valid reasons not to close the connection (as you expect to use it
again in the same function or you're working with a transaction...)

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:(E-Mail Removed)...
>I am also curious. Why it should?
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> www.rthand.com
> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
> SLODUG - Slovene Developer Users Group www.codezone-si.info
>
> "William (Bill) Vaughn" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> No it doesn't and it SHOULD (IMHO).
>>
>>
>> --
>> ____________________________________
>> William (Bill) Vaughn
>> Author, Mentor, Consultant
>> Microsoft MVP
>> www.betav.com/blog/billva
>> www.betav.com
>> Please reply only to the newsgroup so that others can benefit.
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>> __________________________________
>>
>> "Sahil Malik [MVP]" <(E-Mail Removed)> wrote in message
>> news:e$(E-Mail Removed)...
>>> No it doesn't.
>>>
>>> --
>>>
>>> - Sahil Malik [MVP]
>>> ADO.NET 2.0 book -
>>> http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
>>> -------------------------------------------------------------------------------------------
>>>
>>> "WebBuilder451" <(E-Mail Removed)> wrote in
>>> message news:3D41865C-680D-4A70-9999-(E-Mail Removed)...
>>>> does the cmd.ExecuteScalar() auto close the connection the same as
>>>> RxecuteReader(commandbehavior.CloseConnection)?
>>>>
>>>> --
>>>> thanks (as always)
>>>> some day i''m gona pay this forum back for all the help i''m getting
>>>> kes
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ExecuteReader - CommandBehavior.CloseConnection matt@mailinator.com Microsoft ADO .NET 3 4th Dec 2005 04:20 PM
CommandBehavior.CloseConnection question tshad Microsoft ADO .NET 2 13th Oct 2005 06:34 PM
HELP: CommandBehavior.CloseConnection Mark Microsoft C# .NET 0 29th Mar 2005 11:24 AM
commandbehavior.closeconnection with applicationblocks =?Utf-8?B?ZGF2ZQ==?= Microsoft ASP .NET 5 16th Apr 2004 06:59 AM
Understanding CommandBehavior.CloseConnection Michael Microsoft ADO .NET 3 31st Dec 2003 05:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:04 PM.