Opening a Connection

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

    Opening a Connection

    I'm looking at this application I've written and it seems kind of silly how
    many times I open and close a connection to the database.

    Is there a best practice as far as this is concerned? If I open a connection
    in the page load event is there any way I can be sure that its closed off?

    Any thoughts are appreciated,

    Jason


  • Eliyahu Goldin

    #2
    Re: Opening a Connection

    You will save yourself from many problems if you close the connection after
    every data access operation. It is the recommended practice in ADO.NET.
    Put your data access code into try..finally blocks and close the connection
    in the finally.

    Eliyahu

    "Jason MacKenzie" <jmackenzie_nos pam@formet.com> wrote in message
    news:eYs%23%23y MPEHA.1392@TK2M SFTNGP09.phx.gb l...[color=blue]
    > I'm looking at this application I've written and it seems kind of silly[/color]
    how[color=blue]
    > many times I open and close a connection to the database.
    >
    > Is there a best practice as far as this is concerned? If I open a[/color]
    connection[color=blue]
    > in the page load event is there any way I can be sure that its closed off?
    >
    > Any thoughts are appreciated,
    >
    > Jason
    >
    >[/color]


    Comment

    • Kevin Spencer

      #3
      Re: Opening a Connection

      > Is there a best practice as far as this is concerned? If I open a
      connection[color=blue]
      > in the page load event is there any way I can be sure that its closed off?[/color]

      The best way to make sure that the connection is closed is to close it. Make
      that the only way.

      --
      HTH,
      Kevin Spencer
      ..Net Developer
      Microsoft MVP
      Big things are made up
      of lots of little things.

      "Jason MacKenzie" <jmackenzie_nos pam@formet.com> wrote in message
      news:eYs##yMPEH A.1392@TK2MSFTN GP09.phx.gbl...[color=blue]
      > I'm looking at this application I've written and it seems kind of silly[/color]
      how[color=blue]
      > many times I open and close a connection to the database.
      >
      > Is there a best practice as far as this is concerned? If I open a[/color]
      connection[color=blue]
      > in the page load event is there any way I can be sure that its closed off?
      >
      > Any thoughts are appreciated,
      >
      > Jason
      >
      >[/color]


      Comment

      • Jason MacKenzie

        #4
        Re: Opening a Connection

        That's what I always do. Just wanted to see if there was a better way.
        Thanks guys.


        "Eliyahu Goldin" <removemeegoldi n@monarchmed.co m> wrote in message
        news:%23Ha7qANP EHA.3476@tk2msf tngp13.phx.gbl. ..[color=blue]
        > You will save yourself from many problems if you close the connection[/color]
        after[color=blue]
        > every data access operation. It is the recommended practice in ADO.NET.
        > Put your data access code into try..finally blocks and close the[/color]
        connection[color=blue]
        > in the finally.
        >
        > Eliyahu
        >
        > "Jason MacKenzie" <jmackenzie_nos pam@formet.com> wrote in message
        > news:eYs%23%23y MPEHA.1392@TK2M SFTNGP09.phx.gb l...[color=green]
        > > I'm looking at this application I've written and it seems kind of silly[/color]
        > how[color=green]
        > > many times I open and close a connection to the database.
        > >
        > > Is there a best practice as far as this is concerned? If I open a[/color]
        > connection[color=green]
        > > in the page load event is there any way I can be sure that its closed[/color][/color]
        off?[color=blue][color=green]
        > >
        > > Any thoughts are appreciated,
        > >
        > > Jason
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...