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 3976230
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:46:47+00:00 2026-05-20T04:46:47+00:00

I’m hoping somebody will be able to help with my SQLite database problem. I’m

  • 0

I’m hoping somebody will be able to help with my SQLite database problem.

I’m receiving a ConstraintException when querying my SQLite database with C#. The full exception message is “Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.” I originally built this database using access which worked fine, but for various reasons I had to recreate it using SQLite.

To give a bit of background – this is a simple status scheduling program. Each Status has an associated Account and Schedule. I realise Statuses and Schedule is a 1:1 relationship and could be in the same table but to allow the program to develop further I have split them into two tables.

See below for a cut down version of my table script (this is enough to recreate the problem).

PRAGMA foreign_keys = ON;

CREATE TABLE Accounts
(ID INTEGER PRIMARY KEY AUTOINCREMENT,
Name char(100));

CREATE TABLE Statuses
(ID INTEGER PRIMARY KEY AUTOINCREMENT,
AccountId INTEGER REFERENCES Accounts(ID) ON DELETE CASCADE,
Text char(140));

CREATE TABLE Schedule
(ID INTEGER PRIMARY KEY REFERENCES Statuses(ID) ON DELETE CASCADE,
StartDate char(255),
Frequency INT);

I did not have any issues until I created two Statues and associated them to the same Account.

Accounts
ID  Name
1   Fred Blogs

Statuses
ID AccountId Text
1         1          “Some text”
2         1          “Some more text”

Schedule
ID    StartDate     Frequency
1     16/02/2011        1
2     16/02/2011        1

The select statement I’m using which throws the exception is:

SELECT Statuses.Id, Statuses.Text, Accounts.Id, Accounts.Name, Schedule.StartDate, Schedule.Frequency
FROM [Statuses], [Accounts], [Schedule]
WHERE Statuses.AccountId = Accounts.Id AND Statuses.Id = Schedule.Id

If I run the same query, but remove the ‘Accounts.Id’ column the query works fine.

See below for the C# code I’m using but I don’t think this is the problem

public DataTable Query(string commandText)
    {

        SQLiteConnection sqliteCon = new SQLiteConnection(ConnectionString);
        SQLiteCommand sqliteCom = new SQLiteCommand(commandText, sqliteCon);
        DataTable sqliteResult = new DataTable("Query Result");

        try
        {
            sqliteCon.Open();
            sqliteResult.Load(sqliteCom.ExecuteReader());
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            sqliteCon.Close();
        }

        return sqliteResult;

    }

Any help will be appreciated. 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-05-20T04:46:48+00:00Added an answer on May 20, 2026 at 4:46 am

    I have found a way round this problem. If I select the AccountId from the Schedule table rather than the Accounts table there is no exception thrown. It seems I was unable to run a SELECT statement that contained two Unique primary key columns.

    So instead of

    SELECT Statuses.Id, Statuses.Text, Accounts.Id, Accounts.Name, Schedule.StartDate, Schedule.Frequency
    FROM [Statuses], [Accounts], [Schedule]
    WHERE Statuses.AccountId = Accounts.Id AND Statuses.Id = Schedule.Id
    

    I run

    SELECT Statuses.Id, Statuses.Text, Statuses.AccountId, Accounts.Name, Schedule.StartDate, Schedule.Frequency
    FROM [Statuses], [Accounts], [Schedule]
    WHERE Statuses.AccountId = Accounts.Id AND Statuses.Id = Schedule.Id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hoping someone can provide an answer with this, although it's not 100% programming related.
I'm hoping there's a way to avoid custom configuration files if an application runs
I'm hoping to find out what tools folks use to synchronize data between databases.
I'm hoping someone has seen this before because I can't for the life of
I am hoping to find a way to do this in vb.net: Say you
I'm hoping there's something in the same conceptual space as the old VB6 IsNumeric()
I was hoping to implement a simple XMPP server in Java. What I need
I'm hoping that someone has found a way of doing this already or that
I am hoping to dynamically update a ModelForm's inline Meta class from my view.
I'm hoping that it isn't to pass each as a parameter to the controller

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.