Solved

difference between executeCommand() and executeReader()

Posted on 2007-12-04
2
382 Views
Last Modified: 2008-02-01
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
Comment
Question by:arthrex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 20404646
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question