Can't insert into a table with an integer primary key

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for SQLite
Post Reply
killswtch
Posts: 9
Joined: Sat 18 Dec 2010 16:58

Can't insert into a table with an integer primary key

Post by killswtch » Sat 18 Dec 2010 17:47

I've tried everything I can think of, including uninstalling and reinstalling version 3.0 of dotConnect for SQLite. I've also created a very simple (single table, 2 field) database to eliminate the possibility of it being the complexity of the database being a problem.

Whenever I try to insert a row into a table with a primary key set, it fails with the following very unhelpful exception:

Code: Select all

System.InvalidCastException was unhandled
  Message="Specified cast is not valid."
  Source="System.Data.Linq"
  StackTrace:
       at System.Data.Linq.Mapping.MetaAccessor`2.SetBoxedValue(Object& instance, Object value)
       at Devart.Data.Linq.aa.e()
       at Devart.Data.Linq.b.a()
       at Devart.Data.Linq.y.a(DataContext A_0, ConflictMode A_1)
       at Devart.Data.Linq.y.b(DataContext A_0, ConflictMode A_1)
       at Devart.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
       at Devart.Data.Linq.DataContext.SubmitChanges()
       at SqliteLinqTest.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\Simon\Documents\Visual Studio 2008\Projects\SqliteLinqTest\SqliteLinqTest\Form1.cs:line 25
       (Irrelevent stuff removed)
The table has 2 fields:
MyID, an integer PK with autoincrement
Text1, a nullable text field

If I remove autoincrement and set the ID manually, it has no effect. Changing whether it's nullable or not also has no effect. If I remove the PK, the exception goes away.

Here's the test code I'm using:

Code: Select all

			MainDataContext dc = new MainDataContext();

			TestTable tt = new TestTable();
			tt.Text1 = "Some text";

			dc.TestTables.InsertOnSubmit(tt);

			dc.SubmitChanges();
Someone please help, this is driving me nuts!

killswtch
Posts: 9
Joined: Sat 18 Dec 2010 16:58

Post by killswtch » Sat 18 Dec 2010 18:07

Rolled back to the previous build of 3, and then back to 2.9.190 with no change.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Mon 20 Dec 2010 17:25

Thank you for your report. We have reproduced the problem. We will investigate it and inform you about the results as soon as possible.

killswtch
Posts: 9
Joined: Sat 18 Dec 2010 16:58

Post by killswtch » Wed 22 Dec 2010 10:57

Hi. Do you think this problem might be solved this side of Christmas? I'm trying to get this product finished. Thanks.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Thu 23 Dec 2010 13:51

We have fixed this problem, but the build containing the fix will be released in about two weeks.

As a temporary workaround, you can set the data type of the identity fields to Int64 instead of Int32 in the model.

killswtch
Posts: 9
Joined: Sat 18 Dec 2010 16:58

Post by killswtch » Fri 24 Dec 2010 16:59

Thanks, I think the workaround has resolved this particular issue. I think I may have found a new one though. I'll raise in a separate thread.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Wed 12 Jan 2011 17:15

We have released the 3.0.86 version of dotConnect for SQLite which includes the fix for this problem. This build can be downloaded from
http://www.devart.com/dotconnect/sqlite/download.html
(the trial version) or from Registered Users' Area (for users with active subscription only):
http://secure.devart.com/

For the detailed information about the fixes and improvements available in this build, please refer to
http://www.devart.com/forums/viewtopic.php?t=19971

Post Reply