Help debugging exception

Help debugging exception

Postby jerryk » Sat 19 Oct 2013 01:01

Hi,

We are getting an exception caused by one of the fields in an object being null. When we call SaveChanges() the before Insert trigger detects this condition and throws the error.

I need some assistance in determining which of the 3 million or so rows in the entity has the null value. I have a couple of thoughts on how to approach this issue.

  • Try to determine when the faulty row is added to the collection. This has been my approach, but so far no rows look bad when they are added to the collection.
  • Try to determine which rows were are going to be saved when SavedChanges() is called. Only a few of the rows are updated or new. Find the faulty new or updated rows and remove them from the collection.
  • Have dotConnect ignore the exception. It does stop the insert which is fine. I don't know if this is possible.

Any suggestions on how to proceed?
jerryk
 
Posts: 8
Joined: Mon 02 Aug 2010 18:47

Re: Help debugging exception

Postby Shalex » Tue 22 Oct 2013 13:30

jerryk wrote:I need some assistance in determining which of the 3 million or so rows in the entity has the null value.

You can find out the exact command which fails to execute in the following way:

Code: Select all
using Devart.Data.Oracle;
using Devart.Common;

namespace MyConsoleApplication {
    class Program {
        static void Main(string[] args) {
            OracleMonitor myMonitor = new OracleMonitor();
            myMonitor.TraceEvent += new MonitorEventHandler(OnEvent);
            myMonitor.UseApp = false;
            myMonitor.IsActive = true;
            using (MyEntities context = new MyEntities()) {
                DEPT d = new DEPT() { DEPTNO = 1, DNAME = "a", LOC = "a" };
                context.DEPTs.Add(d);
                context.SaveChanges();
            }
            Console.ReadKey();
        }

        public static void OnEvent(object sender, MonitorEventArgs e) {
            if (e.EventType == MonitorEventType.Error) {
                OracleCommand cmd = sender as OracleCommand;
                if (cmd != null) {
                    // analyze here command text and parameters of the exact OracleCommand which fails to execute
                }
            }
        }
    }
}

Please use this code only for debugging because it decreases the performance.

JIC: dotConnect for Oracle includes the Batch Update feature which increases CUD performance: http://blogs.devart.com/dotconnect/new-features-of-entity-framework-support-in-dotconnect-providers.html#Batch. Be aware that each OracleCommand will contain a lot of SQL statements in this case, so the way of debugging described in the code snippet will not help much.
Shalex
Devart Team
 
Posts: 7460
Joined: Thu 14 Aug 2008 12:44


Return to dotConnect for Oracle