Solved

difference between executeCommand() and executeReader()

Posted on 2007-12-04
2
374 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
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SLQ View not updating 10 47
separate column 24 20
Sql query 34 19
How many Lat/Long for a single UK Postcode 5 12
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now