ricojohari
ricojohari

Reputation: 183

Error on Inserting to Ms Access Database (Unspecified Error \r\n Object invalid or no longer set)

I want to insert about 2000 records every time a button is clicked. It works fine until record 511, and throw this exception: Unspecified Error \r\n Object invalid or no longer set

I've debugged it several times with different records or different order and always get the same error on 511th record. What's happening?

CODE: (I read the ID of the last record, before i insert another one)

string CmdText = "SELECT TOP 1 Id FROM MyTable ORDER BY Id DESC";
OleDbCommand com = new OleDbCommand(CmdText,tran.Connection,tran);
com.CommandType = CommandType.Text;
OleDbDataReader reader = com.ExecuteReader(); //exception started here

Upvotes: 4

Views: 1006

Answers (3)

user4726758
user4726758

Reputation: 1

The best way to resolve this problem is to delete that table in which its giving error in inserting / updating. and then re-create the table, but be sure, to backup the table data first.

Upvotes: 0

ricojohari
ricojohari

Reputation: 183

I've figured it out guys. I have to close OleDBDataReader every time i want to insert new record.

Now it works fine. Thanks.

Upvotes: 1

KF2
KF2

Reputation: 10153

It sounds like somehow the Jet engine is not working properly or is corrupted.

When opening and closing connections or recordsets using the Microsoft ODBC Driver for Access or the Microsoft OLE DB Provider for Jet, the following error may be reported:

Object invalid or no longer set.

To resolve this problem, install the latest Microsoft Jet 4.0 service pack 6. For additional information FIX: "Object invalid or no longer set" Error with Microsoft Jet

Upvotes: 1

Related Questions