Results 1 to 5 of 5

Thread: Is this bad? sqlConnection and command [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    Is this bad? sqlConnection and command [RESOLVED]

    I declared a public SqlConnection and SqlCommand in a module and made it public. I re-use those throughout the life of the app and simply open and close as necessary the connection object and change the command.commandText property as needed. Is that better or worse or the same as going through that process time and time again for each function/sub that may need it?
    Last edited by Andy; Aug 13th, 2004 at 11:55 AM.

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Perfectly fine...

    just make sure you check the connection's state property often..

    VB Code:
    1. If SqlConnection1.State = ConnectionState.Open Then SqlConnection1.Close

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    good to know that. i have a routine that checks exactly that and closes it if open. I was worried that my way would not utilize connection pooling correctly and eventually my app would bottleneck.

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Just use the data application block from MS, then you don't need to do that...

    http://msdn.microsoft.com/library/de...ml/daab-rm.asp

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    I can personally vouch for the benefits of the DAABs. Intuitive, easy to use, and efficient. And its basically the same thing you're doing in a very generalized fashion.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width