Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8248345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:09:46+00:00 2026-06-07T23:09:46+00:00

I was trying to use SQLite database using ADO.NET Entity Framework 5 and I

  • 0

I was trying to use SQLite database using ADO.NET Entity Framework 5 and I was able to connect to the SQLite database and was able to query records from a table in database. But When I am trying to insert a record into table the SaveChanges throws an exception

"An error occurred while updating the entries. See the inner exception for details."

Code looks like this:

var connectionStr = string.Format("data source={0};Version=3;UseUTF16Encoding=True;",
    fileName);
var conn = new SQLiteConnection(connectionStr);

this.personDataContext = new PersonDataContext(conn);

var persons = (from person in File.ReadAllLines(fileName)
               let p = person.Split(new[] { ',', ' ' },
                                    StringSplitOptions.RemoveEmptyEntries)
               select new Person
               {
                   ID = Convert.ToInt32(p[0]),
                   Name = p[1],
                   Address = p[2],
                   MobNo = Convert.ToInt32(p[3]),
                   PhNo = Convert.ToInt32(p[4]),
                   Designation = p[5]
               }).ToList();

if (this.personDataContext != null && this.personDataContext.Persons != null)
{
    foreach (var person in persons)
    {
      this.personDataContext.Persons.Add(person);
    }

    var saveFailed = false;

    do
    {
        try
        {
            this.personDataContext.SaveChanges();
        }
        catch (DbUpdateConcurrencyException ex)
        {
            saveFailed = true;
            ex.Entries.Single().Reload();
        }
    }
    while (saveFailed);
}

and when I check the inner exception, then it says that primary key is not defined. So, after defining the primary key into the table, same exception comes every time.

I am attaching the sample application here. Use Open Db to open the sample database first and then try to import the CSV file.

I am using the Code First approach in which I have designed a Model class and connected it with the table in the SQLite database.

Please help in fixing the problem. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:09:49+00:00Added an answer on June 7, 2026 at 11:09 pm

    Try to disable database generated identity for your key property in the Person class:

    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public int ID { get; set; }
    

    To me it looks like you want to supply key values manually (ID = Convert.ToInt32(p[0])) but EF won’t send this value to the database because by default it expects that the ID value is generated in the database. If it isn’t generated in the DB you get the exception. By setting the DatabaseGeneratedOption to None EF will take the value you supply and send it in the INSERT statement to the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use a SQLite database and Entity Framework (with .net framework 3.5). I'm trying
I'm trying to use Induction to connect to my local SQLite database however I've
I've bound data from a SQLite database table to a ListView using a SimpleCursorAdapter
I have been trying to use the hibernate dialect for SQLite from http://code.google.com/p/hibernate-sqlite/ in
I am trying to run a query on a SQLite database that INNER JOIN
I'm trying to insert non-latin data into sqlite database using bind variables using System.Data.SQLite.
I'm trying to use SQLite's C API to open a database and access some
I'm trying to use an offline MBTiles database using Route-Me . To accomplish this,
I'm trying to use SqlAlchemy to make Sqlite database tables inside of Pylons. I'm
I'm trying to use org.sqlite.JDBC to create and update a sqlite database in ant.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.