{{theTime}}

Search This Blog

Total Pageviews

java.sql.SQLException: The INSERT statement conflicted with the FOREIGN KEY constraint "XXXXXFK1"

java.sql.SQLException: The INSERT statement conflicted with the FOREIGN KEY constraint "XXXXXFK1"
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:372)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2988)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2421)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:671)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:613)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:572)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.execute(JtdsPreparedStatement.java:784)

Resolution:   

Check the foreign key constraint and first insert the required record.  If all records are inserted as part of current database transaction, make sure the sequence of inserts are handled correctly and also verify transaction commit levels.

No comments:

Generate Models from SQL Server using Entity Framework Core

To generate models from SQL Server database tables using Entity Framework (EF) in .NET, you can follow the Database-First approach with Ent...