An introduction to using the ADO.NET - SqlCommand Object

  • Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/jwiner/anintroductiontousingtheadonetsqlcommandobject.asp

  • You might want to add that the syntax:

    cmdMyCommand.Parameters("@LastName") = strLastName

    that works just fine under ADO

    doesn't seem to work under ADO.Net.

    Sprocs don't seem to know anything about their parameters until execution. I guess it makes sense when one considers the basic idea behind ADO.Net is to do away with stateful database interactions.

    This change was the cause of some consternation here, as disappearance of the the old syntax does not seem to be documented anywhere.

    Brian Begy

    Chicago Data Solutions


    Brian Begy
    Chicago Data Solutions

  • I know this is just an example that you presented in the article. So I have a recommedation ( learnt over time).

    When you are working with connections to the database using the command object, I would sincerely recommend the following technique . The following practice will keep the connection pool in better control:

    Instead of myCommand.Open(); or myCommand.Close(); directly

    Use this while opening connections:

        if( myCommand.Connection.State == ConnectionState.Closed)

                myCommand.Open();

     

    Use this while closing connections:

        if( myCommand.Connection.State == ConnectionState.Open)

                myCommand.Close();

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply