When creating a person with personservice I get an exception:
Invalid object name 'Customers.CustomerId'.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
.. omitted
Sounds to me like like a missing table? But I have not changed/added/removed any table from the database. What am I missing?
try
{
var company = _personStorage.CurrentSelectedOrganization;
var person = new Person(fieldTemplate.SystemId);
person.MapFrom(model.NewAccount); // firstname, lastname etc
person.LoginCredential.Username = model.NewAccount.Email;
person.LoginCredential.NewPassword = model.NewAccount.Password;
person.OrganizationLinks.Add(new PersonToOrganizationLink(company.SystemId)
{ RoleSystemIds = new HashSet<Guid> { orderApprover.SystemId } });
using (_securityContextService.ActAsSystem())
{
_personService.Create(person);
}
}
catch (Exception e)
{
// do nothing
}
Litium version: 7.3.2
The only thing I can think of is a missing Id on the person.
How do I force the default Id to be stored?
Maybe it is trying to map a value to the Id, that value should be unique which system provides such as LSC100001, LSC100002, etc… you can change the prefix in web.config (LSC).
I know that. But how do I apply the next id?
Even when I don’t use the mapping function I still get the same error.
var person = new Person(fieldTemplate.SystemId)
{
FirstName = model.NewAccount.FirstName,
LastName = model.NewAccount.LastName,
Email = model.NewAccount.Email,
Phone = model.NewAccount.Phone,
LoginCredential = {
Username = model.NewAccount.Email,
NewPassword = model.NewAccount.Password
}
};
I am not sure where you are getting the Customers.CustomerId from.
You are creating a new person, the system will generate that value so no need for you to populate the Id property.
The catch in my first post in this thread are what is giving me that error.
Yes, let me see if I get the same error when using your code in my solution on 7.3 version, I get back to you.
I had issues running my 7.3 version but I tried your code in 7.4 (No changes on Person entity) and there were no issues… not sure why you get that error.
NilsN
February 12, 2020, 2:16pm
10
Did you start with 7.3.2 or have you upgraded from an older version?
Started with clean accelerator 7.2.3. Upgraded database from 6.0.0.
NilsN
February 17, 2020, 3:22pm
12
If you check the database, do you have a sequence called Customers.CustomerId? (under Database > Programmability)
There are no sequences there. I’m guessing that’s wrong.
NilsN
February 17, 2020, 3:43pm
14
Try adding it with this query:
USE [DatabaseName]
GO
CREATE SEQUENCE [Customers].[CustomerId]
AS [bigint]
START WITH 100001
INCREMENT BY 1
MINVALUE 1
CACHE 3
GO
Maybe start with should be different depending on the number of users in the database you upgraded.
Awesome. That solved it it seems. Will double check
Yes, that is wrong so the question is, did you have the sequence there in the original database? The sequence is created in version 6.0.0. If that one is missing, it may also be other part of object that is missing and can cause other issues.
Ok. Will keep an eye on it. Don’t have any more “errors” like this earlier.
What kind of issues?
Hard to pinpoint exact error messages, but sql errors in general. maybe not sql timeout but others.
system
Closed
March 16, 2020, 4:06pm
19
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.