Results 1 to 3 of 3

Thread: Connection Objects

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Question Connection Objects

    I was just wondering why an instance of a connection object is needed when creating a new instance of a command object
    Code:
    objCommand = New sqlClient.SqlCommand(strSQL, New SqlClient.SqlConnection(strConn))
    but one is not need when used as a parameter to a data adapter
    object.

    Code:
    objDA = New SqlClient.SqlDataAdapter(strSql, strConn)
    objDA.fill(objDS)

  2. #2
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    I can only imagine it's to do with the different ways these objects are used. The DataAdapter object can open and close a connection itself which facilitates it's disconnected nature. It does this with a connection object or a connection string and it needs to be able to do this so it can operate in a disconnected mode and reconnect to the datasource when it needs to not continually.
    You can also pass a command object to a dataadapter instead of a connection object/string and it's possible that forcing you to use a connection object with a command is a safety feature to ensure the dataadapter can properly use it.
    Then again your guess is as good as mine and who cares anyway

  3. #3

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Just curious. Usually one needs to create an instance of an object to work with that object. The DataAdapter probably just creates a SqlConnection internally based on the connection string passed in as a arguement. At least that's my guess.

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