2 thread use the same database connection to do transaction
-
-
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
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
-
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
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?
-
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?
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