Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SQLiteException : UNIQUE constraint failed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    SQLiteException : UNIQUE constraint failed

    I have seeing all these messages in the logs, ,I can able to place trades using chart trader without issues.

    How ever its breaking the Addon which I am working. Whats the solution to get around the SqlLite issue.


    Code:
    2024-08-09 03:32:16:031 SQLite error (1555): abort at 40 in [INSERT INTO Executions(Id,Account,BarIndex,Commission,Exchange,ExecutionId,Fee,Instrument,IsEntry,IsEntryStrategy,IsExit,IsExitStrategy,LotSize,MarketPosition,MaxPrice,MinPrice,Name,OrderId,Pos
    2024-08-09 03:32:16:031 (Db) Cbi.DB.DBThread.Exception: error=-1 [execution='7807793|1907251762|1907251762' instrument='MNQ SEP24' account='BX31216-13' exchange=Globex price=18573.75 quantity=1 marketPosition=Long orderId='1907251762' time='2024-08-08 18:02:50' sod=False statementDate='2024-08-08', Add]
    code = Constraint (19), message = System.Data.SQLite.SQLiteException (0x800027AF): constraint failed
    UNIQUE constraint failed: Executions.Id
       at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)
       at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
       at System.Data.SQLite.SQLiteDataReader.NextResult()
       at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
       at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery(CommandBehavior behavior)
       at NinjaTrader.Cbi.Execution.DbAdd()
       at NinjaTrader.Cbi.DB.DBThread()
    2024-08-09 03:32:16:031 ERROR: Error on executing DB command: code = Constraint (19), message = System.Data.SQLite.SQLiteException (0x800027AF): constraint failed UNIQUE constraint failed: Executions.Id    at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)    at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)    at System.Data.SQLite.SQLiteDataReader.NextResult()    at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)    at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)    at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery(CommandBehavior behavior)    at NinjaTrader.Cbi.Execution.DbAdd()    at NinjaTrader.Cbi.DB.DBThread()
    2024-08-09 03:32:26:032 SQLite error (1555): abort at 40 in [INSERT INTO Executions(Id,Account,BarIndex,Commission,Exchange,ExecutionId,Fee,Instrument,IsEntry,IsEntryStrategy,IsExit,IsExitStrategy,LotSize,MarketPosition,MaxPrice,MinPrice,Name,OrderId,Pos
    2024-08-09 03:32:26:034 (Db) Cbi.DB.DBThread.Exception: error=-1 [execution='7807792|1907251762|1907251762' instrument='MNQ SEP24' account='BX31216-13' exchange=Globex price=18573.5 quantity=2 marketPosition=Long orderId='1907251762' time='2024-08-08 18:02:50' sod=False statementDate='2024-08-08', Add]
    code = Constraint (19), message = System.Data.SQLite.SQLiteException (0x800027AF): constraint failed
    UNIQUE constraint failed: Executions.Id
       at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)
       at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
       at System.Data.SQLite.SQLiteDataReader.NextResult()
       at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
       at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery(CommandBehavior behavior)
       at NinjaTrader.Cbi.Execution.DbAdd()
       at NinjaTrader.Cbi.DB.DBThread()
    2024-08-09 03:32:26:034 ERROR: Error on executing DB command: code = Constraint (19), message = System.Data.SQLite.SQLiteException (0x800027AF): constraint failed UNIQUE constraint failed: Executions.Id    at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)    at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)    at System.Data.SQLite.SQLiteDataReader.NextResult()    at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)    at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)    at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery(CommandBehavior behavior)    at NinjaTrader.Cbi.Execution.DbAdd()    at NinjaTrader.Cbi.DB.DBThread()
    2024-08-09 03:32:36:035 SQLite error (1555): abort at 40 in [INSERT INTO Executions(Id,Account,BarIndex,Commission,Exchange,ExecutionId,Fee,Instrument,IsEntry,IsEntryStrategy,IsExit,IsExitStrategy,LotSize,MarketPosition,MaxPrice,MinPrice,Name,OrderId,Pos
    2024-08-09 03:32:36:037 (Db) Cbi.DB.DBThread.Exception: error=-1 [execution='7806825|1907250302|1907250302' instrument='MNQ SEP24' account='BX31216-11' exchange=Globex price=18551.75 quantity=1 marketPosition=Short orderId='1907250302' time='2024-08-08 18:00:47' sod=False statementDate='2024-08-08', Add]
    code = Constraint (19), message = System.Data.SQLite.SQLiteException (0x800027AF): constraint failed
    UNIQUE constraint failed: Executions.Id
       at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)
       at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
       at System.Data.SQLite.SQLiteDataReader.NextResult()
       at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
       at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery(CommandBehavior behavior)
       at NinjaTrader.Cbi.Execution.DbAdd()
       at NinjaTrader.Cbi.DB.DBThread()
    2024-08-09 03:32:36:037 ERROR: Error on executing DB command: code = Constraint (19), message = System.Data.SQLite.SQLiteException (0x800027AF): constraint failed UNIQUE constraint failed: Executions.Id    at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)    at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)    at System.Data.SQLite.SQLiteDataReader.NextResult()    at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)    at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)    at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery(CommandBehavior behavior)    at NinjaTrader.Cbi.Execution.DbAdd()    at NinjaTrader.Cbi.DB.DBThread()
    2024-08-09 03:32:46:038 SQLite error (1555): abort at 40 in [INSERT INTO Executions(Id,Account,BarIndex,Commission,Exchange,ExecutionId,Fee,Instrument,IsEntry,IsEntryStrategy,IsExit,IsExitStrategy,LotSize,MarketPosition,MaxPrice,MinPrice,Name,OrderId,Pos
    2024-08-09 03:32:46:038 (Db) Cbi.DB.DBThread.Exception: error=-1 [execution='7807791|1907251762|1907251762' instrument='MNQ SEP24' account='BX31216-13' exchange=Globex price=18573 quantity=1 marketPosition=Long orderId='1907251762' time='2024-08-08 18:02:50' sod=False statementDate='2024-08-08', Add]
    code = Constraint (19), message = System.Data.SQLite.SQLiteException (0x800027AF): constraint failed
    UNIQUE constraint failed: Executions.Id
       at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)
       at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
       at System.Data.SQLite.SQLiteDataReader.NextResult()
       at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
       at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery(CommandBehavior behavior)
       at NinjaTrader.Cbi.Execution.DbAdd()
       at NinjaTrader.Cbi.DB.DBThread()​

    #2
    Hello Kdevineni,

    Thank you for your post.

    Is this error only happening when running your AddOn script or a specific script? If it's happening when running a specific script, you'll need to debug the script. I would start by commenting out code line by line until the behavior stops. Then, uncomment comment code until the error returns. What was the last line uncommented?​

    Or is it happening even when you are not running any scripts? In that case, it may be related to the database. To rename the database:
    • Shutdown NinjaTrader
    • Open the Documents > NinjaTrader 8 > db folder
    • Right click on NinjaTrader.sqlite and select "Rename"
    • Rename the file 'OLDNinjaTrader.sqlite'
    • Finally, restart NinjaTrader
    • Unfortunately the following items stored in the old database will be lost - Trading Hours templates, Instrument Lists / Custom Instruments, historical trade execution data, saved Strategy Analyzer backtest results

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    553 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    100 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    543 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    546 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X