SubmitChanges throws Object reference not set to an instance of an object

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
appletonr
Posts: 3
Joined: Mon 20 May 2013 08:37

SubmitChanges throws Object reference not set to an instance of an object

Post by appletonr » Mon 20 May 2013 09:14

Hi!
There is a similar issue with the same subject, only it's on LinqConnect (LINQ to SQL support). I had posted this there, but moved it.

I'm getting the same error in a similar situation. In my case I'm updating a record. I have no problems with inserts. This piece of code was working fine and I'm only getting this error since I upgraded from devart 6.3 to 7.5 (dot connect for Oracle).
The query does return the record sought.

Code: Select all

void ibtnApproveLine_Click(object sender, ImageClickEventArgs e)
{
	try
	{
		using (SsinpatDataContext dc = new SsinpatDataContext())
		{
			string[] ids = ((ImageButton)sender).ID.Split('_');
			decimal idOrcamento = decimal.Parse(ids[1].ToString());
			decimal idAgregador = decimal.Parse(ids[2].ToString());
			decimal idArtigo = decimal.Parse(ids[3].ToString());

			EapSsArtigosOrcamento ao = dc.EapSsArtigosOrcamento.SingleOrDefault(x => x.IdAgregador == idAgregador
								&& x.IdOrcamento == idOrcamento
								&& x.IdArtigo == idArtigo);

			ao.Aprovado = 1;

			approveBlocksUpward(dc, idOrcamento, idAgregador, false);

			dc.SubmitChanges(); // <<=== This is where the exception is thrown
			EscreveDetalheOrcamento(dc);
		}
	}
	catch (Exception exp)
	{
		log.Error(exp.Message);
		log.Error(exp.InnerException);
		throw exp;
	}
}
approveBlocksUpward is a recursive function that sets the flag Aprovado to 1 to all records on the same or upper levels.

Code: Select all

private void approveBlocksUpward(SsinpatDataContext dc, decimal idOrcamento, decimal idAgregador, bool flag = true)
{
	try
	{
		//get the current block
		var aos = from a in dc.EapSsAgregadoresOrcamento
				  where a.IdAgregador == idAgregador
				  && a.IdOrcamento == idOrcamento
				  select a;
		foreach (var ao in aos)
		{
			ao.Aprovado = 1;

			if (ao.IdAgregadorPai != null)
			{
				approveBlocksUpward(dc, idOrcamento, ao.IdAgregadorPai, false);
			}
		}
	}
	catch (Exception exp)
	{
		log.Error(exp.Message);
		log.Error(exp.InnerException);
		throw exp;
	}
}
Now, I'm puzzled because I don't really know where to look.
Thanks for your help.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: SubmitChanges throws Object reference not set to an instance of an object

Post by MariiaI » Tue 21 May 2013 08:13

According to your post, you have just upgraded your version of dotConnect for Oracle. Basically, we have made a major refactoring of the LinqConnect engine since version 4.0 (dotConnect for Oracle 7.0.6) and since this version the references to System.Data.Linq are removed, and LinqConnect uses only its own classes. So it is necessary to replace all occurrences of "System.Data.Linq." with "Devart.Data.Linq.".

If you are still getting the error after these changes, please send us a sample project, with which this error could be reproduced.

appletonr
Posts: 3
Joined: Mon 20 May 2013 08:37

Re: SubmitChanges throws Object reference not set to an instance of an object

Post by appletonr » Tue 21 May 2013 09:37

Ok, it didn't work. I'm posting the stack trace of the exception while I setup a sample project, hoping it might help find the source of the matter:
at Devart.Data.Linq.Engine.MultiKeyManager`3.CreateKeyFromValues(Object[] values)
at Devart.Data.Linq.Engine.KeyManager`2.b(Object[] A_0)
at Devart.Data.Linq.Engine.c5.a(MetaDataMember A_0, Object A_1)
at Devart.Data.Linq.Engine.av.a(Object A_0, MetaAssociation A_1, IObjectEntry& A_2)
at Devart.Data.Linq.Engine.av.a()
at Devart.Data.Linq.Engine.av.b()
at Devart.Data.Linq.Engine.av.a(IObjectEntry[] A_0)
at Devart.Data.Linq.Engine.b4.b(IObjectEntry[] A_0)
at Devart.Data.Linq.Engine.b4.a(ConflictMode A_0)
at Devart.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at Devart.Data.Linq.DataContext.SubmitChanges()
at Vistorias.App_Pages.Orcamentos.DetOrcamentos.ibtnApproveLine_Click(Object sender, ImageClickEventArgs e) in C:\Workspace\Development\Smartsinpat\Vistorias\Vistorias\App_Pages\Orcamentos\DetOrcamentos.aspx.cs:line 1185
These are the assemblies I'm currently referencing (I've now upgraded to the latest 7.7 version):
Devart.Data v5.0.701.0
Devart.Data.Linq v4.2.247.0
Devart.Data.Oracle v7.7.242.0
Devart.Data.Oracle.Linq v4.2.247.0

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: SubmitChanges throws Object reference not set to an instance of an object

Post by MariiaI » Tue 21 May 2013 11:55

Thank you for the additional information.
The bug with inserting record with a composite primary key ("Devart.Data.Linq.Engine.MultiKeyManager`3.CreateKeyFromValues(Object[] values)") was fixed in dotConnect for Oracle 7.7.242. Thus, please upgrade your dotConnect for Oracle to the latest one and notify us about the results.

New build can be downloaded from http://www.devart.com/dotconnect/oracle/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=1&t=27136.

appletonr
Posts: 3
Joined: Mon 20 May 2013 08:37

Re: SubmitChanges throws Object reference not set to an instance of an object

Post by appletonr » Wed 22 May 2013 09:23

Sigh... I tried it, but to no avail. I couldn't replicate the error on a project made from scatch. It probably is related to something within the model... I managed to narrow down the scope of the error, but in the end I worked it around by executing a SQL statement

Code: Select all

string sqlStmt = "UPDATE ... WHERE COL_A = {0} AND COL_B = {1}";
object[] pars = new object[2];
pars[0] = ao.IdA;
pars[1] = ao.IdB;
dc.ExecuteCommand(sqlStmt, pars);
Thanks for everything

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: SubmitChanges throws Object reference not set to an instance of an object

Post by MariiaI » Thu 23 May 2013 07:55

We couldn't reproduce this issue with a similar code. If possible, please send us your model and the exact SQL query("sqlStmt"), so that we are able to investigate this issue and find the solution for you.
JIC: you can try reducing your model up to the entity classes, that are involved in the query, and the entity classes, which depend on them.

Post Reply