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
  1. Home
  2. Database & SysAdmin
  3. Database
  4. 2 thread use the same database connection to do transaction

2 thread use the same database connection to do transaction

Scheduled Pinned Locked Moved Database
databasesql-serversysadminhelpquestion
4 Posts 2 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.
  • T Offline
    T Offline
    ting668
    wrote on last edited by
    #1

    Hi Is there any problem if 2 threads use the same database SQL Server CE 2000 connection do transaction at the same time? If 1 threads capture the right to do the transaction, then is the other thread will wait for access or what others happen? Thanks

    C 1 Reply Last reply
    0
    • T ting668

      Hi Is there any problem if 2 threads use the same database SQL Server CE 2000 connection do transaction at the same time? If 1 threads capture the right to do the transaction, then is the other thread will wait for access or what others happen? Thanks

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

      I'm assuming that SQL Server CE 2000 is sufficiently similar to the full SQL Server 2000 product that this answer is valid - Considering you are using a cut down version I cannot see how it would have enhanced functionality. So here goes... If you use 2 threads and operate on the same connection then you have to be careful only to run one command at a time on the connection. Remember that the DataReader is running the command until you exhaust the data being returned. If you attempt to run a second command at the same time as an existing command is running an exception will be thrown. So, the answer is: It won't wait, it will throw an exception.


      Do you want to know more? WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums

      T 1 Reply Last reply
      0
      • C Colin Angus Mackay

        I'm assuming that SQL Server CE 2000 is sufficiently similar to the full SQL Server 2000 product that this answer is valid - Considering you are using a cut down version I cannot see how it would have enhanced functionality. So here goes... If you use 2 threads and operate on the same connection then you have to be careful only to run one command at a time on the connection. Remember that the DataReader is running the command until you exhaust the data being returned. If you attempt to run a second command at the same time as an existing command is running an exception will be thrown. So, the answer is: It won't wait, it will throw an exception.


        Do you want to know more? WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums

        T Offline
        T Offline
        ting668
        wrote on last edited by
        #3

        Then how about 2 thread hold 2 objects respectively and the objects contains a database connection respectively and the 2 connections are different object reference but they also connect to the same database? Will exception be thrown if the 1 object is doing transaction and the other object try to connect to the database?

        C 1 Reply Last reply
        0
        • T ting668

          Then how about 2 thread hold 2 objects respectively and the objects contains a database connection respectively and the 2 connections are different object reference but they also connect to the same database? Will exception be thrown if the 1 object is doing transaction and the other object try to connect to the database?

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

          That would probably be fine. I don't know about SQL Server CE, but in the full server product you can do that.


          Do you want to know more? WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums

          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