VistaDB 5 Saving issue

2 posts, 1 answers
  1. Mike
    Mike avatar
    4 posts
    Member since:
    Jan 2015

    Posted 14 Apr 2015 Link to this post

     

     Hi,

    I am trying to save en entity with child entities and i am getting the below error and not sure why or how to fix it.

    I have 2 tables ApplicationUser and ApplicationUserPermission. I have created a new instance of ApplicationUser called currentUser and have added in some new permissions as follows.

     

    attach it the context

    uow.Add(currentUser);

    uow.SaveChanges();

    I have a foreign key constraint between the two tables

    The exception i am getting is

    "Insert of '1195119920-' failed: Telerik.OpenAccess.RT.sql.SQLException: \r\nError 170 (Provider v. 5.0.7.1369): Expression statement failed  \r\nError 172 (Provider v. 5.0.7.1369): Cannot pass constraint:  FOREIGN KEY REFERENCES ( 'ApplicationUser' )\r\nError 341 (Provider v. 5.0.7.1369): Cannot execute script after inserting a new row \r\nError 250 (Provider v. 5.0.7.1369): Cannot create row:  \nTable: 'ApplicationUserPermission', RowId = 2\n\r\n ---> VistaDB.Diagnostic.VistaDBException: \r\nError 170 (Provider v. 5.0.7.1369): Expression statement failed  \r\nError 172 (Provider v. 5.0.7.1369): Cannot pass constraint:  FOREIGN KEY REFERENCES ( 'ApplicationUser' )\r\nError 341 (Provider v. 5.0.7.1369): Cannot execute script after inserting a new row \r\nError 250 (Provider v. 5.0.7.1369): Cannot create row:  \nTable: 'ApplicationUserPermission', RowId = 2\n\r\n ---> VistaDB.Diagnostic.VistaDBException: \r\nError 170 (Provider v. 5.0.7.1369): Expression statement failed  \r\nError 172 (Provider v. 5.0.7.1369):
     Cannot pass constraint:  FOREIGN KEY REFERENCES ( 'ApplicationUser' )\r\nError 341 (Provider v. 5.0.7.1369): Cannot execute script after inserting a new row \r\n ---> VistaDB.Diagnostic.VistaDBException: \r\nError 170 (Provider v. 5.0.7.1369): Expression statement failed  \r\nError 172 (Provider v. 5.0.7.1369): Cannot pass constraint:  FOREIGN KEY REFERENCES ( 'ApplicationUser' )\r\n ---> VistaDB.Diagnostic.VistaDBException: \r\nError 170 (Provider v. 5.0.7.1369): Expression statement failed  \r\n\r\n   at VistaDB.Engine.Core.DataStorage.PassFilter(Filter filter, Row activeRow)\r\n   --- End of inner exception stack trace ---\r\n   at VistaDB.Engine.Core.DataStorage.PassFilter(Filter filter, Row activeRow)\r\n   at VistaDB.Engine.Core.DataStorage.PassAfterCreateFilters()\r\n   --- End of inner exception stack trace ---\r\n   at VistaDB.Engine.Core.DataStorage.CreateRow(Boolean commit, Boolean blank)\r\n   at VistaDB.Engine.Core.Table.Create(Boolean commit, Boolean empty)\r\n   --- End of inner exception stack
     trace ---\r\n   at VistaDB.Engine.SQL.BatchStatement.CheckBatchExceptions()\r\n   at VistaDB.Engine.SQL.BatchStatement.NextResult(VistaDBPipe pipe)\r\n   at VistaDB.Provider.VistaDBDataReader.ExecQuery(Int64& affectedRows)\r\n   at VistaDB.Provider.VistaDBCommand.ExecQuery(Int64& affectedRows)\r\n   at VistaDB.Provider.VistaDBCommand.ExecuteNonQuery()\r\n   at OpenAccessRuntime.CommandWrapper.ExecuteNonQuery()\r\n   at Telerik.OpenAccess.Runtime.Logging.LoggingDbCommand.ExecuteNonQuery()\r\n   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.CommandImp.ExecuteNonQuery()\r\n   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute(Nullable`1 commandTimeout)\r\n   --- End of inner exception stack trace ---\r\n   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute(Nullable`1 commandTimeout)\r\n   at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute(Nullable`1 commandTimeout)\r\n   at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObje
    ctOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes, BatchControlInfo batchControl)\nINSERT INTO [ApplicationUserPermission] ([ModuleId], [UserId], [CanCreate], [CanDelete], [CanPrint], [CanRead], [CanUpdate]) VALUES (?, ?, ?, ?, ?, ?, ?)\n(set event logging to all to see parameter values) Telerik.OpenAccess.RT.sql.SQLException: \r\nError 170 (Provider v. 5.0.7.1369): Expression statement failed  \r\nError 172 (Provider v. 5.0.7.1369): Cannot pass constraint:  FOREIGN KEY REFERENCES ( 'ApplicationUser' )\r\nError 341 (Provider v. 5.0.7.1369): Cannot execute script after inserting a new row \r\nError 250 (Provider v. 5.0.7.1369): Cannot create row:  \nTable: 'ApplicationUserPermission', RowId = 2\n\r\n ---> VistaDB.Diagnostic.VistaDBException: \r\nError 170 (Provider v. 5.0.7.1369): Expression statement failed  \r\nError 172 (Provider v. 5.0.7.1369): Cannot pass constraint:  FOREIGN KEY REFERENCES ( 'ApplicationUser' )\r\nError 3
    41 (Provider v. 5.0.7.1369): Cannot execute script after inserting a new row \r\nError 250 (Provider v. 5.0.7.1369): Cannot create row:  \nTable: 'ApplicationUserPermission', RowId = 2\n\r\n ---> VistaDB.Diagnostic.VistaDBException: \r\nError 170 (Provider v. 5.0.7.1369): Expression statement failed  \r\nError 172 (Provider v. 5.0.7.1369): Cannot pass constraint:  FOREIGN KEY REFERENCES ( 'ApplicationUser' )\r\nError 341 (Provider v. 5.0.7.1369): Cannot execute script after inserting a new row \r\n ---> VistaDB.Diagnostic.VistaDBException: \r\nError 170 (Provider v. 5.0.7.1369): Expression statement failed  \r\nError 172 (Provider v. 5.0.7.1369): Cannot pass constraint:  FOREIGN KEY REFERENCES ( 'ApplicationUser' )\r\n ---> VistaDB.Diagnostic.VistaDBException: \r\nError 170 (Provider v. 5.0.7.1369): Expression statement failed  \r\n\r\n   at VistaDB.Engine.Core.DataStorage.PassFilter(Filter filter, Row activeRow)\r\n   --- End of inner exception stack trace ---\r\n   at VistaDB.Engine.Core.DataStorage.PassFilt
    er(Filter filter, Row activeRow)\r\n   at VistaDB.Engine.Core.DataStorage.PassAfterCreateFilters()\r\n   --- End of inner exception stack trace ---\r\n   at VistaDB.Engine.Core.DataStorage.CreateRow(Boolean commit, Boolean blank)\r\n   at VistaDB.Engine.Core.Table.Create(Boolean commit, Boolean empty)\r\n   --- End of inner exception stack trace ---\r\n   at VistaDB.Engine.SQL.BatchStatement.CheckBatchExceptions()\r\n   at VistaDB.Engine.SQL.BatchStatement.NextResult(VistaDBPipe pipe)\r\n   at VistaDB.Provider.VistaDBDataReader.ExecQuery(Int64& affectedRows)\r\n   at VistaDB.Provider.VistaDBCommand.ExecQuery(Int64& affectedRows)\r\n   at VistaDB.Provider.VistaDBCommand.ExecuteNonQuery()\r\n   at OpenAccessRuntime.CommandWrapper.ExecuteNonQuery()\r\n   at Telerik.OpenAccess.Runtime.Logging.LoggingDbCommand.ExecuteNonQuery()\r\n   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.CommandImp.ExecuteNonQuery()\r\n   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute(Nullable`1 commandTimeout)\r\n
       --- End of inner exception stack trace ---\r\n   at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.execute(Nullable`1 commandTimeout)\r\n   at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.execute(Nullable`1 commandTimeout)\r\n   at OpenAccessRuntime.Relational.RelationalStorageManager.generateInserts(NewObjectOID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, CharBuf s, Object[] oidData, IntArray toUpdateIndexes, BatchControlInfo batchControl)"

  2. Answer
    Doroteya
    Admin
    Doroteya avatar
    502 posts

    Posted 15 Apr 2015 Link to this post

    Hi Mike,

    Thank you for contacting us.

    Based on the stack trace and the provided information, my best guess about the cause of the error is that the ApplicationUser.ApplicationUserPermissions navigation property is not configured to be managed by Data Access.

    For a navigation property, being managed means that Telerik Data Access tracks additions and removals of items in the collection and issues the proper statements during SaveChanges(). By default, the one-to-many associations are not managed for performance reasons.

    To configure the association on your side properly, you need to set the IsManaged property of ApplicationUser.ApplicationUserPermissions to True. How to achieve this is described in the How to: Manage One-to-Many Associations article.

    I hope this helps. Let us know if you need further information.


    Regards,
    Doroteya
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  3. DevCraft banner
Back to Top