tags:

views:

346

answers:

4

Hi I'm using OracleCommand.ExecuteNonQuery() to insert into a table. Everything works fine but occasionally records are not inserted. So is it possible that ExecuteNonQuery() doesn't insert the record and also doesn't throw an exception?

I'm not using stored procedures. I'm not using a transaction. I am logging any exception that is thrown by ExecuteNonQuery() but apparently no exception is thrown... I am also not checking the return value of ExecuteNonQuery(). But is it possible that ExecuteNonQuery returns another value than 1 if the insert is successful?

+2  A: 

It shouldn't. ExecuteNonQuery returns an integer indicating the number of rows affected. If no rows were inserted, 0 should be returned. It should thrown an exception when it fails to execute the query. E.x.: the connection is closed, the table doesn't exist, etc.

hjb417
Is there any documentation stating that checking for the Exception is sufficient to know the error for (INSERT, UPDATE, DELETE) operations? Can I just ignore the return value and just depend on the catch statement. Also, in the MSDN documentation it states that exception are not thrown in .NET 1.1, but it did not state that exception are sure to be thrown on .NET 2.0 afterwards.
Nassign
+1  A: 

It's quite unlikely.

Do you have a error handler at a higher level which might be catching the error, and throwing it away?

Bravax
+2  A: 

Not unless you're swallowing the exception somewhere, like this:

try
{
   DoSomethingOnTheDbThatMightThrowAnException();
}
catch(Exception ex)
{
   // Do nothing, thus swallowing the exception
}

Also, check the return value of ExecuteNonQuery(). If it is 0, you might want to consider throwing an exception yourself.

Neil Barnwell
+1  A: 

"Everything works fine but occasionally records are not inserted." Possibly inserting into/through a view which can allow you to insert records which you can't actually see. Virtual Private Database/Row Level Security can do this too.

Gary