multiple database save error

Posts   
 
    
Posts: 14
Joined: 07-Dec-2006
# Posted on: 18-Dec-2006 17:13:45   

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(List1 userRoles) in C:\VS2005Projects\DEDEnterprise\EnterpriseServiceFacade\EnterpriseUserPortals\ EnterpriseUserPortalsMethods.cs:line 257" string

Any help that can be provided would be appreciated.

Cory

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 18-Dec-2006 17:25:55   

Hello,

just before the save instruction, what is the value of userid?

Posts: 14
Joined: 07-Dec-2006
# Posted on: 18-Dec-2006 17:27:12   

All the values of the entity seem to be correct. The value of userId in this case is number 19.

Posts: 14
Joined: 07-Dec-2006
# Posted on: 18-Dec-2006 18:05:06   

I think the issue relates to the code not generating a connection string for each catalog. Does LLBLGen support this?

Posts: 14
Joined: 07-Dec-2006
# Posted on: 18-Dec-2006 20:38:01   

Figured it out. Found a similar problem in the following thread...turns out we had the same issue...

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7539