Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

difference between executeCommand() and executeReader()

Posted on 2007-12-04
2
Medium Priority
?
384 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 1500 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

Independent Software Vendors: 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!

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

719 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