Re: Wii close connection?



I found it, not so much confusing, as misleading to talk about the fact that
the connection will stay open until the GC gets its hands on the connection.
As we've discussed, connection pooling could keep the GC away from the
object indefinitely.



"Chris Taylor" <chris_taylor_za@xxxxxxxxxxx> wrote in message
news:OE1budkrFHA.1984@xxxxxxxxxxxxxxxxxxxxxxx
> Is it not true that the GC will take care of it eventually? Of course it
> is,
> I never stated that this is a good thing I am just stating that it will
> happen.
>
> As for the connection pooling issue, I believe this is beyond what the
> poster was asking for.
> But yes it is true that the underlying connection is not physically
> closed,
> however the resource
> is being released and being made available for reuse by other code within
> the AppDomain.
> This happens regardless of the managed connection being finalized or
> explicitly calling Dispose or Close.
>
> Again I state however:
> "You should explicitly close the connection..." ie. call Close or Dispose
> on
> the managed connection object.
>
> Hope this clarifies any confusion my original response might have caused.
>
> --
> Chris Taylor
> http://dotnetjunkies.com/weblog/chris.taylor
>
>
> "Scott M." <s-mar@xxxxxxxxxxxxx> wrote in message
> news:epAg8UbrFHA.1252@xxxxxxxxxxxxxxxxxxxxxxx
>> But, that changes when connection pooling (the default) is used. My
>> point
>> was that it is confusing and not really the best answer to say that the
>> GC
>> will take care of it.
>>
>>
>> "Chris Taylor" <chris_taylor_za@xxxxxxxxxxx> wrote in message
>> news:OHwjnuarFHA.3864@xxxxxxxxxxxxxxxxxxxxxxx
>> > Yes, however once the GC process will eventually invoke the finalizer
>> > which
>> > in turn calls Dispose and therefore the connection will be closed.
>> >
>> > --
>> > Chris Taylor
>> > http://dotnetjunkies.com/weblog/chris.taylor
>> >
>> >
>> > "Scott M." <s-mar@xxxxxxxxxxxxx> wrote in message
>> > news:#isuiRarFHA.3640@xxxxxxxxxxxxxxxxxxxxxxx
>> >> Please note that the Garbage Collection of the connection object in
>> >> memory
>> >> and the closing of the Connection object (to the data source) are not
> the
>> >> same thing.
>> >>
>> >> He should explicitly close the connection when he's done with it and
> then
>> >> the object can be destroyed based on memory management rules.
>> >>
>> >> "Chris Taylor" <chris_taylor_za@xxxxxxxxxxx> wrote in message
>> >> news:uvr5HOarFHA.3796@xxxxxxxxxxxxxxxxxxxxxxx
>> >> > Hi,
>> >> >
>> >> > No, the connection will linger until such time as the garbage
>> >> > collection
>> >> > process ie. Finalization etc. takes care of releasing the connection
>> >> > object.
>> >> > You should explicitly close the connection, preferably by using a
>> >> > try/finally block to ensure the connection is closed regardless of
>> > errors,
>> >> > for C# I like the using statement to assist with this.
>> >> >
>> >> > public int object MyExecuteNonQuery(string sSql)
>> >> > {
>> >> > string cnnStr="....";
>> >> > int iRV;
>> >> > using(SqlConnection cnn = new SqlConnection(cnnStr))
>> >> > {
>> >> > SqlCommand myCommand = new SqlCommand(sSql, cnn);
>> >> > cnn.Open();
>> >> > iRV=myCommand.ExecuteNonQuery;
>> >> > } // At this point the cnn object will be disposed
>> >> > return iRV;
>> >> > }
>> >> >
>> >> > Hope this helps
>> >> >
>> >> > --
>> >> > Chris Taylor
>> >> > http://dotnetjunkies.com/weblog/chris.taylor
>> >> >
>> >> >
>> >> > "ad" <flying@xxxxxxxxxxxxxxx> wrote in message
>> >> > news:#r1TpGarFHA.304@xxxxxxxxxxxxxxxxxxxxxxx
>> >> >> I have a function call MyExecuteNonQuery(see bellow)
>> >> >> When I call it with some Sql command like:
>> >> >> MyExecuteNonQuery("Delete from myTable);
>> >> >> Will it close the conneciton which opened in MyExecuteNonQuery?
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >>
>>
>>>> ------------------------------------------------------------------------
> -
>> > -
>> >> > --
>> >> >> public int object MyExecuteNonQuery(string sSql)
>> >> >> {
>> >> >> string cnnStr="....";
>> >> >> SqlConnection cnn = new SqlConnection(cnnStr);
>> >> >> SqlCommand myCommand = new SqlCommand(sSql, cnn);
>> >> >> cnn.Open();
>> >> >> int iRV=myCommand.ExecuteNonQuery;
>> >> >> return iRV;
>> >> >>
>> >> >> }
>> >> >> /*
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >>
>> >
>> >
>>
>>
>
>


.



Relevant Pages

  • Re: try backing the beachs unwilling objective and Ikram will taste you
    ... They are confusing in connection with the ... trap now, won't shut courts later. ...
    (sci.crypt)
  • Re: asp.net, vs2k5, getting started connecting to databases... Im confused
    ... It's a bit confusing when you first get started and the short answer ... Depending on how you want to display the data in your webparts, ... // this with the current connection. ... // Close data reader object and database connection ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: disposing SqlCommand and SqlConnection
    ... If the SqlConnection goes out of scope, ... close the connection by calling Close or Dispose. ... If the connection pooling value Pooling is set to true or yes, ...
    (microsoft.public.dotnet.framework)
  • Re: Dispose vs Close
    ... or dispose (by virtue of calling close) would make the ... Instead of passing Connection Objects - consider passing connectionstrings ... for connection pooling. ...
    (microsoft.public.dotnet.framework.adonet)
  • Bluetooth DUN on my new phone
    ... I used to have a Nokia phone and I had a ... Dial-up connection to *99# for an internet connection. ... SGH-D407 which are Edge 10 phones and bluetooth enabled. ... bluetooth and one thing that is confusing is the number to dial. ...
    (alt.cellular.cingular)

Loading