12

During an update command I received the following error:

Operation is not valid due to the current state of the object

I tried to remove one column from the update command and it works fine. This column is a FK that is similar to the other FK that works fine.

This is the code that executes the update:

                ti.NumeroTitolo = titolo.Numero;
                ti.RKTipoTitoloGenereTitolo = titolo.RkTipoTitoloGenereTitolo;
                ti.RKBanca = titolo.RkBanca;
                ti.DataScadenza = titolo.DataScadenza;
                ti.RKTipoEsito = titolo.RkTipoEsito; 
                ti.ImportoTitolo = titolo.ImportoTitolo;

                _dc.SubmitChanges();
GEOCHET
  • 21,119
  • 15
  • 74
  • 98
Salvatore Di Fazio
  • 705
  • 2
  • 7
  • 25

3 Answers3

5

Grenade's answer actually helped me because I was coming across this exception when attempting to reassign a foreign key. The relationship/constraint was preventing the key from being reassigned.

However, I was able to access the relationship item directly and reassign it, thereby reassigning the foreign key.

product.manufacturer_id = manufacturerID; //This caused the above exception

product.Manufacturer = new Manufacturer(manufacturerID);
//or
product.Manufacturer = OtherManufacturer;
Ryan Cannon
  • 59
  • 2
  • 2
0

The problem may be caused by a relationship or other constraint. For example if you are attempting to drop a row who's Id is referenced by some other table with a relationship. Perhaps if you post the SQL or LINQ query that is giving the error we can help you more.

grenade
  • 31,451
  • 23
  • 97
  • 126
0

I was getting the same error trying to create a subscription. Found this post:

I was also having this issue. I found a good post that told how to add a key to the web.config file in the folder C:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting Services\ReportManager.

I had to remove the <> to make it show.

add key="aspnet:MaxHttpCollectionKeys" value="10000"

http://social.msdn.microsoft.com/Forums/ar-SA/sqlreportingservices/thread/c9d4431a-0d71-4782-8f38-4fb4d5b7a829

CW1255
  • 113
  • 1
  • 1
  • 6