question about using connection

Discussion in 'ASP .Net' started by Eric, Mar 7, 2009.

  1. Eric

    Eric Guest

    Hi,

    i use this for a database connection:

    Using mConnection As New SqlConnection(param.ConnectionString)
    mConnection.Open()
    sql = "insert ...."
    comd = New SqlCommand(sql, mConnection)
    comd.ExecuteNonQuery()
    End Using

    My question is: do i need to close the connection with: mConnection.Close()
    or does the End Using do itself?

    thanks
    Eric
     
    Eric, Mar 7, 2009
    #1
    1. Advertising

  2. Eric

    Andy B. Guest

    The end using statement closes it. If you don't use the using statement you
    would have to close it yourself.
    "Eric" <> wrote in message
    news:%...
    > Hi,
    >
    > i use this for a database connection:
    >
    > Using mConnection As New SqlConnection(param.ConnectionString)
    > mConnection.Open()
    > sql = "insert ...."
    > comd = New SqlCommand(sql, mConnection)
    > comd.ExecuteNonQuery()
    > End Using
    >
    > My question is: do i need to close the connection with:
    > mConnection.Close() or does the End Using do itself?
    >
    > thanks
    > Eric
    >
    >
     
    Andy B., Mar 7, 2009
    #2
    1. Advertising

  3. Eric

    Eric Guest

    thanks

    "Andy B." <> schreef in bericht
    news:%...
    > The end using statement closes it. If you don't use the using statement
    > you would have to close it yourself.
    > "Eric" <> wrote in message
    > news:%...
    >> Hi,
    >>
    >> i use this for a database connection:
    >>
    >> Using mConnection As New SqlConnection(param.ConnectionString)
    >> mConnection.Open()
    >> sql = "insert ...."
    >> comd = New SqlCommand(sql, mConnection)
    >> comd.ExecuteNonQuery()
    >> End Using
    >>
    >> My question is: do i need to close the connection with:
    >> mConnection.Close() or does the End Using do itself?
    >>
    >> thanks
    >> Eric
    >>
    >>

    >
    >
     
    Eric, Mar 7, 2009
    #3
  4. Find here more details:

    http://stackoverflow.com/questions/376068/does-end-using-close-an-open-sql-connection


    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin


    "Eric" <> wrote in message
    news:...
    > thanks
    >
    > "Andy B." <> schreef in bericht
    > news:%...
    >> The end using statement closes it. If you don't use the using statement
    >> you would have to close it yourself.
    >> "Eric" <> wrote in message
    >> news:%...
    >>> Hi,
    >>>
    >>> i use this for a database connection:
    >>>
    >>> Using mConnection As New SqlConnection(param.ConnectionString)
    >>> mConnection.Open()
    >>> sql = "insert ...."
    >>> comd = New SqlCommand(sql, mConnection)
    >>> comd.ExecuteNonQuery()
    >>> End Using
    >>>
    >>> My question is: do i need to close the connection with:
    >>> mConnection.Close() or does the End Using do itself?
    >>>
    >>> thanks
    >>> Eric
    >>>
    >>>

    >>
    >>

    >
    >
     
    Eliyahu Goldin, Mar 8, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mythran
    Replies:
    5
    Views:
    5,001
    Mythran
    Oct 5, 2005
  2. Dave Johnson

    Using Connection Class VS Connection Module

    Dave Johnson, Dec 9, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    660
    Dave Johnson
    Dec 11, 2005
  3. Linus Nikander
    Replies:
    5
    Views:
    562
  4. Replies:
    3
    Views:
    40,668
    Roedy Green
    Nov 16, 2005
  5. R
    Replies:
    1
    Views:
    592
Loading...

Share This Page