Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

difference between executeCommand() and executeReader()

Hi experts,

I have a select statement that I want to commit to the database. Parallely I created a manual lock on the dataset which I used in my select statement. To commit the select statement I used the method executeReader() first. Since that method throws an SQLException I expected it to throw it - but it didn't. After I couldn't figure out why it doesn't throw the exception, I tried using the executeCommand() method. That worked. It threw the SQLException as expected. But when I tried to use a select statement on another dataset in that table, it also threw the exception.
My questions:
1) Why doesn't the executeReader() method throw an exception when the executeCommand() method does?
2) To me it seems that executeCommand() puts a lock on the whole table whereas executeReader() only locks the specific dataset. Is that correct?
3) Can someone give some advice to the optimal solution for my problem?

Thanks a lot!
0
arthrex
Asked:
arthrex
1 Solution
 
dqmqCommented:
1.  Both ExecuteReader and ExecuteCommand use the same command/connection objects under the covers. So, I do not understand why one would fail and the other not.  The only thing that comes to mind is that the executeReader is not set up properly and is raising a higher level exception.

2.  No.  

3. What's the exception?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now