Pooling and SqlConnetion?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • perspolis

    #1

    Pooling and SqlConnetion?

    Hi all
    I use 'Pooling=true;' in my connection string;
    how can I disable 'pooling' in my application and close all connections???
    thanks in advance


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Pooling and SqlConnetion?

    perspolis,

    I wouldn't necessarily do that. What is the purpose here? Just killing
    a database connection is a bad thing, since you could be closing it in the
    middle of an important operation.

    You can always just not place "pooling=tr ue" in the connection string,
    and the connections will not be pooled, they will close when your code
    closes them.

    Of course, you should always use the using statement to make sure your
    connections close when you are done using them.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "perspolis" <rezarms@hotmai l.com> wrote in message
    news:eizlWOEHGH A.532@TK2MSFTNG P15.phx.gbl...[color=blue]
    > Hi all
    > I use 'Pooling=true;' in my connection string;
    > how can I disable 'pooling' in my application and close all connections???
    > thanks in advance
    >[/color]


    Comment

    • Peter Bromberg [C# MVP]

      #3
      RE: Pooling and SqlConnetion?

      Pooling=true is the default, it will be on even if this element is not
      present in the connection string. change it to:

      Pooling=false;

      Now as long as you Close each connection, no connections will be returned to
      the pool. I think its important to understand that pooled connection objects
      are just connection objects, they are not left "Open" - until you open them.

      Why do you want to disable connection pooling?

      Peter

      --
      Co-founder, Eggheadcafe.com developer portal:

      UnBlog:





      "perspolis" wrote:
      [color=blue]
      > Hi all
      > I use 'Pooling=true;' in my connection string;
      > how can I disable 'pooling' in my application and close all connections???
      > thanks in advance
      >
      >
      >[/color]

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Pooling and SqlConnetion?

        Nicholas Paldino [.NET/C# MVP] wrote:[color=blue]
        > I wouldn't necessarily do that. What is the purpose here? Just killing
        > a database connection is a bad thing, since you could be closing it in the
        > middle of an important operation.
        >
        > You can always just not place "pooling=tr ue" in the connection string,
        > and the connections will not be pooled, they will close when your code
        > closes them.
        >
        > Of course, you should always use the using statement to make sure your
        > connections close when you are done using them.[/color]

        That doesn't make sure the physical connections will be closed though.

        Before now I've had cause to want to remove connections from the pool
        having killed them on the SQL Server side (if you're not careful, the
        pool doesn't notice that they've died, and you get an exception next
        time you try to use them).

        Fortunately, in .NET 2.0 you can use SqlConnection.C learAllPools (or
        ClearPool for a specific pool) to do this. Unfortunately I wasn't
        working with 2.0 at the time :(

        Jon

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: Pooling and SqlConnetion?

          Jon Skeet [C# MVP] wrote:[color=blue][color=green]
          > > Of course, you should always use the using statement to make sure your
          > > connections close when you are done using them.[/color]
          >
          > That doesn't make sure the physical connections will be closed though.[/color]

          Just to anticipate a reply - yes, it will kill the physical connections
          if you have pooling turned off to start with. I hadn't noticed that bit
          of Nick's reply :)

          Jon

          Comment

          Working...