Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Why can't use 2 DataReader with same connection

Why can't use 2 DataReader with same connection

Scheduled Pinned Locked Moved Database
question
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Heinz_
    wrote on last edited by
    #1

    That's it, Why can't i use 2 DataReader with same connection? How can i do multiple queries from the same connection. Thanks.

    C S 2 Replies Last reply
    0
    • H Heinz_

      That's it, Why can't i use 2 DataReader with same connection? How can i do multiple queries from the same connection. Thanks.

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Heinz_ wrote:

      How can i do multiple queries from the same connection

      Just open a second identical connection to run the second command.


      Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

      H 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Heinz_ wrote:

        How can i do multiple queries from the same connection

        Just open a second identical connection to run the second command.


        Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

        H Offline
        H Offline
        Heinz_
        wrote on last edited by
        #3

        Hi, i just did it but that second connection is what i have been trying to avoid. I remember that with ADODB in VB6 i was able to do multiple command and reads from the same connection. Thanx, it works this way anyway.

        C 1 Reply Last reply
        0
        • H Heinz_

          Hi, i just did it but that second connection is what i have been trying to avoid. I remember that with ADODB in VB6 i was able to do multiple command and reads from the same connection. Thanx, it works this way anyway.

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          Heinz_ wrote:

          i just did it but that second connection is what i have been trying to avoid.

          Why?

          Heinz_ wrote:

          I remember that with ADODB in VB6 i was able to do multiple command and reads from the same connection.

          ADO.NET is not ADODB.


          Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

          E 1 Reply Last reply
          0
          • C Colin Angus Mackay

            Heinz_ wrote:

            i just did it but that second connection is what i have been trying to avoid.

            Why?

            Heinz_ wrote:

            I remember that with ADODB in VB6 i was able to do multiple command and reads from the same connection.

            ADO.NET is not ADODB.


            Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

            E Offline
            E Offline
            Ennis Ray Lynch Jr
            wrote on last edited by
            #5

            If you have a connection you can execute multiple commands on it. Also, keep in mind, that idenctical connection strings will use the connection pool. A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

            C 1 Reply Last reply
            0
            • E Ennis Ray Lynch Jr

              If you have a connection you can execute multiple commands on it. Also, keep in mind, that idenctical connection strings will use the connection pool. A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              Ennis Ray Lynch, Jr. wrote:

              If you have a connection you can execute multiple commands on it

              But not at the same time, which is what the OP wanted to do.

              Ennis Ray Lynch, Jr. wrote:

              Also, keep in mind, that idenctical connection strings will use the connection pool.

              Absolutely!


              Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

              H 1 Reply Last reply
              0
              • C Colin Angus Mackay

                Ennis Ray Lynch, Jr. wrote:

                If you have a connection you can execute multiple commands on it

                But not at the same time, which is what the OP wanted to do.

                Ennis Ray Lynch, Jr. wrote:

                Also, keep in mind, that idenctical connection strings will use the connection pool.

                Absolutely!


                Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

                H Offline
                H Offline
                Heinz_
                wrote on last edited by
                #7

                Understood. I was trying to use only one connection to gain performance but now i replaced the second connection with a subquery in a command of the original connection, check this tasty and parameter rich query: "select SUM(t1.total - COALESCE(t2sum,0)) from ventas as t1 left join (select venta, SUM(cantidad_pagada) as t2sum from pagos_ventas where fecha_pago='" + CDC.Global.SetDBdate(hoy) + "' and metodo_pago<>1 and metodo_pago<>7 group by venta) as t2 on t2.venta=t1.id where t1.nula=0 and t1.pagada=0 and t1.fecha='" + CDC.Global.SetDBdate(hoy) + "'" Bye. -- modified at 15:29 Tuesday 18th July, 2006

                C 1 Reply Last reply
                0
                • H Heinz_

                  Understood. I was trying to use only one connection to gain performance but now i replaced the second connection with a subquery in a command of the original connection, check this tasty and parameter rich query: "select SUM(t1.total - COALESCE(t2sum,0)) from ventas as t1 left join (select venta, SUM(cantidad_pagada) as t2sum from pagos_ventas where fecha_pago='" + CDC.Global.SetDBdate(hoy) + "' and metodo_pago<>1 and metodo_pago<>7 group by venta) as t2 on t2.venta=t1.id where t1.nula=0 and t1.pagada=0 and t1.fecha='" + CDC.Global.SetDBdate(hoy) + "'" Bye. -- modified at 15:29 Tuesday 18th July, 2006

                  C Offline
                  C Offline
                  Colin Angus Mackay
                  wrote on last edited by
                  #8

                  I don't see any parameters in your query - What I do see is lots of SQL Injection that is ripe for attack. A parameter is something like this:

                  SELECT * FROM Table WHERE something = @Parameter

                  @Parameter is the parameter. You might like to read about SQL Injection Attacks, what they are, what damage they can do, and most importantly, how to prevent them: http://www.codeproject.com/cs/database/SqlInjectionAttacks.asp[^]


                  Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

                  H 1 Reply Last reply
                  0
                  • C Colin Angus Mackay

                    I don't see any parameters in your query - What I do see is lots of SQL Injection that is ripe for attack. A parameter is something like this:

                    SELECT * FROM Table WHERE something = @Parameter

                    @Parameter is the parameter. You might like to read about SQL Injection Attacks, what they are, what damage they can do, and most importantly, how to prevent them: http://www.codeproject.com/cs/database/SqlInjectionAttacks.asp[^]


                    Scottish Developers events: * .NET debugging, tracing and instrumentation by Duncan Edwards Jones and Code Coverage in .NET by Craig Murphy * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

                    H Offline
                    H Offline
                    Heinz_
                    wrote on last edited by
                    #9

                    Hi, i used the wrong word but you know what i mean, thanks for the link.

                    1 Reply Last reply
                    0
                    • H Heinz_

                      That's it, Why can't i use 2 DataReader with same connection? How can i do multiple queries from the same connection. Thanks.

                      S Offline
                      S Offline
                      sampathkumarg
                      wrote on last edited by
                      #10

                      Multiple Active Result Sets (MARS). Probable you need ADO.Net 2.0.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups