Those are for me always much more important than any technical benefit.
> Again, this is true for ASP--not necessarily for connected Windows Forms
> applications and not at all for SQLCe applications or other single-user
> DBMS engine applications.
>
> --
> ____________________________________
> William (Bill) Vaughn
> Author, Mentor, Consultant
> Microsoft MVP
> INETA Speaker
>
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.
> __________________________________
> Visit
www.hitchhikerguides.net to get more information on my latest book:
> Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
> and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
> -----------------------------------------------------------------------------------------------------------------------
>
> "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
> news:4656A36E-2352-47DF-98D4-4C870D040B5F@microsoft.com...
>> The definition is open as late as possible and close it as soon as
>> possible. That doesn't imply that you should open and close connection
>> for each command. It rather implies that you have to open the connection
>> right before doing database operations and close it asap you finished
>> with database operation*s*.
>> Opening and closing for each operation doesn't make sense.
>> --
>> Miha Markic [MVP C#, INETA Country Leader for Slovenia]
>> RightHand .NET consulting & development
www.rthand.com >> Blog:
http://cs.rthand.com/blogs/blog_with_righthand/ >>
>> "Andrew Robinson" <nemoby@nospam.nospam> wrote in message
>> news:Omn6GgpNHHA.4244@TK2MSFTNGP04.phx.gbl...
>>> Bill,
>>>
>>> This is an asp.net app so lets call it scenario 3.0 and I understand
>>> that we want to tie up the thread pool for as short a period of time as
>>> possible. But, if I am going to execute 2 or 3 "command.ExecuteQuery()"
>>> methods (one after the next), are you still saying that we should open
>>> and close between each of them?
>>>
>>> I tend to say but not sure that is based on a performance requirement
>>> but more just on a best practice standpoint. You never know when you
>>> will get bumped out of the current thread pool and by slicing in as fine
>>> grained a programming model as possible we are allowing the system to
>>> perform at its best.
>>>
>>> Pretty sure I know the answer here but will feel better knowing the king
>>> of all things sql agrees.
>>>
>>>
>>> Thanks again.
>>>
>>> -Andy
>>>
>>> "William (Bill) Vaughn" <billvaRemoveThis@nwlink.com> wrote in message
>>> news:etBt8FfNHHA.4916@TK2MSFTNGP06.phx.gbl...
>>>> And then there is Scenario 2.5:
>>>> Your company has a LAN and it has to support a thousand (typically
>>>> far fewer) active connections as applications come and go during the
>>>> day. In this case since SS can handle these connections with ease, it's
>>>> fine to open and keep a large number of connections open indefinitely.
>>>>
>>>> And Scenario 3.0
>>>> Your company supports a web site which is running ASP applications.
>>>> In this case the way that the applications are instantiated and torn
>>>> down after they're used dictate that you open and quickly close
>>>> connections as they are used. In this case the connections are handled
>>>> by the Connection Pool which is used to hold a limited number of
>>>> connections open so the overhead of connecting is minimized.
>>>>
>>>> --
>>>> ____________________________________
>>>> William (Bill) Vaughn
>>>> Author, Mentor, Consultant
>>>> Microsoft MVP
>>>> INETA Speaker
>>>>
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.
>>>> __________________________________
>>>> Visit
www.hitchhikerguides.net to get more information on my latest
>>>> book:
>>>> Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
>>>> and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
>>>> -----------------------------------------------------------------------------------------------------------------------
>>>>
>>>> "Stephany Young" <noone@localhost> wrote in message
>>>> news:e11kDoeNHHA.5000@TK2MSFTNGP03.phx.gbl...
>>>>> It is all a matter of choice, but there a number of factors tht you
>>>>> would need to consider when making that choice, for example:
>>>>>
>>>>> Scenario 1:
>>>>>
>>>>> Your application 'talks' to Sql Server (maybe Express) on the same
>>>>> machine and no other application accesses that Sql Server at all.
>>>>>
>>>>> In this case there is never going to be any contention for connection
>>>>> resources and it would be quite safe to open the connection once and
>>>>> leave it open.
>>>>>
>>>>> Scenario 2:
>>>>>
>>>>> Your application 'talks' to Sql Server on a networked server and that
>>>>> application is installed and in continual use on 10000 other machines
>>>>> on the networks all 'talking' to the same Sql Server.
>>>>>
>>>>> In this case there is going to be contention for connection resources
>>>>> and it would be probably be quite unsafe to open the connection once
>>>>> and leave it open.
>>>>>
>>>>>
>>>>> As you can see there are best case and worst case scenarios and there
>>>>> will be a series of 'shades' in between.
>>>>>
>>>>> As far as benchmarks are concerned, simply time how long it takes to
>>>>> connect the first time and then time how long it takes to connect
>>>>> subsequently, Because of connection pooling and other factors I think
>>>>> you will find that there is little significant overhead in this
>>>>> respect but the time it takes to connect is only one factor.
>>>>>
>>>>>
>>>>> "Andrew Robinson" <nemoby@nospam.nospam> wrote in message
>>>>> news:%23sAcGSdNHHA.4928@TK2MSFTNGP06.phx.gbl...
>>>>>>I recently got into a discussion with a coworker about just how long
>>>>>>to leave a connection open. I have always opened as late as I can and
>>>>>>closed at the earliest possible point in time.
>>>>>>
>>>>>> using (SqlConnection cn = new SqlConnection(DataConnection))
>>>>>> using (SqlCommand cm = new SqlCommand(InsertCommandText, cn))
>>>>>> {
>>>>>> cm.CommandType = InsertCommandType;
>>>>>>
>>>>>> cn.Open();
>>>>>> cm.ExecuteNonQuery();
>>>>>> cn.Close();
>>>>>> }
>>>>>>