We have a VS2005 C# project that accesses two databases...
Database A contains specific user information. We are trying to insert a record into database B with the same UserId from Database A. Both databases use the same SQL server account, so access is not an issue. I used LLBLGen to bring tables from both databases together. For example, the LLBLGen project has DatabaseA.UserTable1 and DatabaseB.UserTable2. UserTable2.UserId is a FK to UserTable1.UserId. When we try to insert a record into DatabaseB.UserTable2 using our code:
private void CreateTMSUser(int userId)
{
TmsUsersCollection tmsUserCollection = new TmsUsersCollection();
IPredicateExpression tmsUserFilter = new PredicateExpression();
tmsUserFilter.Add(new FieldCompareValuePredicate(
TmsUsersFields.UserId, ComparisonOperator.Equal, userId));
tmsUserCollection.GetMulti(tmsUserFilter);
if (tmsUserCollection.Items.Count == 0)
{
// Create the TMS User if they do not already exist
TmsUsersEntity tmsUser = new TmsUsersEntity();
tmsUser.UserId = userId;
tmsUser.DateChanged = DateTime.Now;
tmsUser.DateCreated = DateTime.Now;
tmsUser.UserChanged = _authenticatedUserId;
tmsUser.UserCreated = _authenticatedUserId;
tmsUser.IsNew = true;
tmsUser.IsFullTimeEmployee = false;
tmsUser.IsProjectCoder = false;
tmsUser.UploadToSam2 = false;
tmsUser.UploadToDcar = false;
tmsUser.IsActive = false;
tmsUser.Save(true);
}
}
we get the following error:
Message "An exception was caught during the execution of an action query: Cannot insert the value NULL into column 'USER_ID', table 'tms_portal.dbo.TMS_USERS'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception."
Source "SD.LLBLGen.Pro.ORMSupportClasses.NET20" string
StackTrace " at SD.LLBLGen.Pro.ORMSupportClasses.ActionQuery.Execute()\r\n at SD.LLBLGen.Pro.ORMSupportClasses.BatchActionQuery.Execute()\r\n at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.ExecuteActionQuery(IActionQuery queryToExecute, ITransaction containingTransaction)\r\n at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.AddNew(IEntityFields fields, ITransaction containingTransaction)\r\n at ENTERPRISEDAL.EntityClasses.TmsUsersEntityBase.InsertEntity() in C:\\VS2005Projects\\DEDEnterprise\\EnterpriseDAL\\EntityBaseClasses\\TmsUsersEntityBase.cs:line 1191\r\n at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.CallInsertEntity()\r\n at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PersistQueue(List1 queueToPersist, Boolean insertActions, ITransaction transactionToUse)\r\n at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.Save(IPredicate updateRestriction, Boolean recurse)\r\n at ENTERPRISEDAL.EntityClasses.TmsUsersEntityBase.Save(IPredicate updateRestriction, Boolean recurse) in C:\\VS2005Projects\\DEDEnterprise\\EnterpriseDAL\\EntityBaseClasses\\TmsUsersEntityBase.cs:line 215\r\n at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.Save(Boolean recurse)\r\n at EnterpriseServiceFacade.EnterpriseUserPortals.CreateTMSUser(Int32 userId) in C:\\VS2005Projects\\DEDEnterprise\\EnterpriseServiceFacade\\EnterpriseUserPortals\\ EnterpriseUserPortalsMethods.cs:line 59\r\n at EnterpriseServiceFacade.EnterpriseUserPortals.Save(List
1 userRoles) in C:\VS2005Projects\DEDEnterprise\EnterpriseServiceFacade\EnterpriseUserPortals\ EnterpriseUserPortalsMethods.cs:line 257" string
Any help that can be provided would be appreciated.
Cory