Nullable value called

Hello Support,

After having great success with the SQLite authentication database I moved the table over to MSSQL database. Had a few issues with data types, and field lengths (especially NVarchar(?)). To resolve the issue I checked the lengths in SQLite Browser and went through each table to see what data lengths were used in the example SQLite DB.

Note for those who are new to this the best NVarchar field that replaces SQLite’s TEXT field type would be N VarChar(Max). But you cannot use NVarChar(Max) as an indexed field! After checking the lengths of the text placed in the fields in the example database I picked up that NVarchar(100) would suffice for most of the fields except for the Data field in the table sx_Storage_Items. This does need to be NVarchar(Max). However, if you are not willing to use this field type then set the NVarchar(800) in order for the data supplied does not get truncated. It does produce an error if the field is too small.

Once I had all the fields and field types sorted, when I tried to log in I got an error message from a function that is called in module BCL.Types.Nullable called Function Nullable.GetValue:T;

I went back and checked all the tables and I can’t see why the error is been produced and I am not sure which process it tries to run and is unable to set a field value as Null. However, what I can see is that the sx_user_tokens table is not populated after trying to login. I noted that all the fields in this table are not nullable.

Error: Project TutAuth.exe raised exception class ENullConvertException with message 'Nullable: Cannot convert SNull into string'.

What data is the code trying to write to the database and what field is it trying to check or set to Null?

Regards

Tom Dalton

I understand you have created all tables and columns by yourself in MSSQL?

If that’s the case, you shouldn’t have to do that, Sphinx (Aurelius, under the hood) creates them for you, just like it did with SQLite database. So, if you did that, restart from scratch and let Aurelius create the correct tables and columns with their respective data types.

If your problem still persists, please provide the call stack at the moment of the error.

Hi Wagner,

Sorry, Yes, I did see my error and reverted to letting the module create the tables. I deleted all the tables I created and let the Sphinx create them.

However, I still get the error on a null value.

Call stack:

:00007FFC254EFE4C RaiseException
@InternalRaiseAtExcept(??,??,??)
@RaiseExcept(??)
Nullable<System.string>.GetValue({FValue='',FHasValue=false},'')
Nullable<System.string>.&op_Implicit({FValue='',FHasValue=false},'')
TForm3.SphinxConfig1ConfigureToken($000002dabd714f20,??,$000002dabed03bc0)
TSphinxConfig.NotifyConfigureToken($000002dabd798030,$000002dabec4e888,$000002dabe779090,$000002dabec6e2f0)
TConfigTokenBuilder.DoConfigureToken($000002dabec6d790,$000002dabec4e888,$000002dabe779090,$000002dabec6e2f0)
TJwtTokenBuilder.BuildToken($000002dabec6d790,$000002dabec74110,$000002dabec4e888)
TTokenEndpoint.ProcessAuthorizationCodeFlow($000002dabecdff60)
TTokenEndpoint.ProcessGrantType($000002dabecdff60)
TTokenEndpoint.Process($000002dabecdff60)
TAuthorizationService.Token($000002dabec6ded0,$000002dabf84b7a0)
RawInvoke(??,??)
Invoke($0000000000cffcd3,{[0]={FTypeInfo=$6f6874754149150f,FValueData=$6e6f6974617a6972,{FAsPointer=$d865636976726553,FAsMethod={Code=$d865636976726553,Data=$0900000000002333},FAsSInt64=-2853765484259416749,FAsUInt64=15592978589450134867,FAsCurr=-2.85377e+14,FAsComp=-2.85377e+14,FAsExtended=-6.7419442536812971E+117,FAsDouble=-6.7419442536812971E+117}}},ccReg,$0000000000bdc280,false,false,{FTypeInfo=nil,FValueData=nil,{FAsPointer=$010002dabecafc80,FAsMethod={Code=$010002dabecafc80,Data=$000000fa591fed20},FAsSInt64=72060732565027968,FAsUInt64=72060732565027968,FAsCurr=7.20607e+12,FAsComp=7.20607e+12,FAsExtended=7.2962031515266874E-304,FAsDouble=7.2962031515266874E-304,FAsSingle=-0.396457672}})
TRttiIntfMethod.DispatchInvoke($000002dabe6c7e30,{FTypeInfo=$0000000000bdc480,FValueData=$000002dabed08a50,{FAsPointer=nil,FAsMethod={Code=nil,Data=nil},FAsSInt64=0,FAsUInt64=0,FAsCurr=0,FAsComp=0,FAsExtended=0,FAsDouble=0,FAsSingle=0,FAsSLong=0,FAsSWord=0,FAsSByte=0,FAsClass=$0000000000000000,FAsObject=nil,FAsULong=0,FAsUWord=0,FAsUByte=0}},{[0]={FTypeInfo=$0000000000bdbb60,FValueData=$0000000000f7b830,{FAsPointer=$000002dabf84b7a0,FAsMethod={Code=$000002dabf84b7a0,Data=nil},FAsSInt64=3138539272096,FAsUInt64=3138539272096,FAsCurr=3.13854e+08,FAsComp=3.13854e+08,FAsExtended=1.5506444324662261E-311,FAsDouble=1.5506444324662261E-311,FAsSingle=-1.03685379,FAsSLong=-1081821280}}},{FTypeInfo=nil,FValueData=nil,{FAsPointer=$010002dabecafc80,FAsMethod={Code=$010002dabecafc80,Data=$000000fa591fed20},FAsSInt64=72060732565027968,FAsUInt64=72060732565027968,FAsCurr=7.20607e+12,FAsComp=7.20607e+12,FAsExtended=7.2962031515266874E-304,FAsDouble=7.2962031515266874E-304,FAsSingle=-0.396457672}})
TRttiMethod.Invoke($000002dabe6c7e30,{FTypeInfo=$0000000000bdc480,FValueData=$000002dabed08a50,{FAsPointer=nil,FAsMethod={Code=nil,Data=nil},FAsSInt64=0,FAsUInt64=0,FAsCurr=0,FAsComp=0,FAsExtended=0,FAsDouble=0,FAsSingle=0,FAsSLong=0,FAsSWord=0,FAsSByte=0,FAsClass=$0000000000000000,FAsObject=nil,FAsULong=0,FAsUWord=0,FAsUByte=0}},{[0]={FTypeInfo=$0000000000bdbb60,FValueData=$0000000000f7b830,{FAsPointer=$000002dabf84b7a0,FAsMethod={Code=$000002dabf84b7a0,Data=nil},FAsSInt64=3138539272096,FAsUInt64=3138539272096,FAsCurr=3.13854e+08,FAsComp=3.13854e+08,FAsExtended=1.5506444324662261E-311,FAsDouble=1.5506444324662261E-311,FAsSingle=-1.03685379,FAsSLong=-1081821280}}},{FTypeInfo=nil,FValueData=nil,{FAsPointer=$010002dabecafc80,FAsMethod={Code=$010002dabecafc80,Data=$000000fa591fed20},FAsSInt64=72060732565027968,FAsUInt64=72060732565027968,FAsCurr=7.20607e+12,FAsComp=7.20607e+12,FAsExtended=7.2962031515266874E-304,FAsDouble=7.2962031515266874E-304,FAsSingle=-0.396457672}})
TActionExecuter.Execute($000002dabec693a0)
TXDataRequestHandler.ExecuteAction($000002dabecff160)
TXDataBaseRequestHandler.TryExecuteAction($000002dabecff160,$000002dabec7afd0)
TXDataBaseRequestHandler.InnerProcessRequest($000002dabecff160)
TXDataBaseRequestHandler.ProcessRequest($000002dabecff160)
TXDataBaseModule.ProcessRequest($000002dabd791fb0,$000002dabec476f0)
TBaseHttpServerModule.Execute$ActRec.$0$Body($000002dabec6f3d0,$000002dabec476f0)
TInjectionMiddleware<Sphinx.AuthorizationCode.IAuthorizationCodeStorage>.ProcessRequest($000002dabec4e440,$000002dabec476f0,$000002dabec6f3f0)
THttpServerMiddleware.MiddlewareFunc$ActRec.$0$Body($000002dabec73a90,$000002dabec476f0)
TInjectionMiddleware<Sphinx.LoginAppTransaction.ITransactionStorage>.ProcessRequest($000002dabec4e490,$000002dabec476f0,$000002dabec73ab8)
THttpServerMiddleware.MiddlewareFunc$ActRec.$0$Body($000002dabec6ec90,$000002dabec476f0)
TInjectionMiddleware<Sphinx.Storage.IStoragePersistence>.ProcessRequest($000002dabec4e4e0,$000002dabec476f0,$000002dabec6ecb8)
THttpServerMiddleware.MiddlewareFunc$ActRec.$0$Body($000002dabec6e590,$000002dabec476f0)
TSingletonInjectionMiddleware<Bcl.Logging.ILogger>.ProcessRequest($000002dabec6d650,$000002dabec476f0,$000002dabec6e5b8)
THttpServerMiddleware.MiddlewareFunc$ActRec.$0$Body($000002dabec6e790,$000002dabec476f0)
TSingletonInjectionMiddleware<Sphinx.UIOptions.IUIOptions>.ProcessRequest($000002dabec6d690,$000002dabec476f0,$000002dabec6e7b8)
THttpServerMiddleware.MiddlewareFunc$ActRec.$0$Body($000002dabec6e650,$000002dabec476f0)
TSphinxServerModule.AfterConstruction$ActRec.$3$Body($000002dabec474b0,$000002dabec476f0,$000002dabec6e678)
TAnonymousMiddleware.ProcessRequest($000002dabec6d5d0,$000002dabec476f0,$000002dabec6e678)
THttpServerMiddleware.MiddlewareFunc$ActRec.$0$Body($000002dabec6db10,$000002dabec476f0)
TInjectionMiddleware<Sphinx.IssuerProvider.IIssuerProvider>.ProcessRequest($000002dabec4e580,$000002dabec476f0,$000002dabec6db38)
THttpServerMiddleware.MiddlewareFunc$ActRec.$0$Body($000002dabec6df10,$000002dabec476f0)
TSingletonInjectionMiddleware<Sphinx.CoreOptions.ICoreOptions>.ProcessRequest($000002dabec6d6d0,$000002dabec476f0,$000002dabec6df38)
THttpServerMiddleware.MiddlewareFunc$ActRec.$0$Body($000002dabec6e3d0,$000002dabec476f0)
TInjectionMiddleware<Sphinx.ClientFacade.IClientFacadeProvider>.ProcessRequest($000002dabec4e620,$000002dabec476f0,$000002dabec6e3f8)
THttpServerMiddleware.MiddlewareFunc$ActRec.$0$Body($000002dabec734d0,$000002dabec476f0)
TSingletonInjectionMiddleware<Sphinx.UIOptions.IUIOptions>.ProcessRequest($000002dabec6d750,$000002dabec476f0,$000002dabec734f8)
THttpServerMiddleware.MiddlewareFunc$ActRec.$0$Body($000002dabec6e310,$000002dabec476f0)
TSingletonInjectionMiddleware<Sphinx.TokenBuilder.ITokenBuilder>.ProcessRequest($000002dabec6d7d0,$000002dabec476f0,$000002dabec6e338)
THttpServerMiddleware.MiddlewareFunc$ActRec.$0$Body($000002dabec711d0,$000002dabec476f0)
TSingletonInjectionMiddleware<Sphinx.UserManagerFactory.IUserManagerFactory>.ProcessRequest($000002dabec6d850,$000002dabec476f0,$000002dabec711f8)
THttpServerMiddleware.MiddlewareFunc$ActRec.$0$Body($000002dabec73810,$000002dabec476f0)
TBaseHttpServerModule.Execute($000002dabd791fb0,$000002dabec476f0)
THttpDispatcher.ProcessRequest($000002dabe7aa5a0,$000002dabec476f0)
THttpDispatcher.DispatchRequest($000002dabe7aa5a0,$000002dabec476f0)
TCustomHttpSysServer.DoProcessRequest($000002dabe79f430,$000002dabec476f0)
TCustomHttpSysServer.WorkItemCallBack($000002dabe79f430,$000002dabec652c0)
WorkItemFunction($000002dabec6d9d0)
:00007FFC281FCED1 RtlQueueWorkItem
:00007FFC281E5E46 RtlClearThreadWorkOnBehalfTicket
:00007FFC2730257D BaseThreadInitThunk

As requested.

It seems that it is not getting the user token written or read from the database.
Regards

Tom

Hello Wagner,
I have managed to isolate the issue. Mark van der Berg had used Access_Level token in his ConfigureToken statement. I am not sure if the database was configured correctly to write this value or retrieve this value. Hence the error.

procedure TForm3.SphinxConfig1ConfigureToken(Sender: TObject;
Args: TConfigureTokenArgs);
begin
Args.Token.Claims.AddOrSet('preferred_username', TSphinxUserEx(Args.User).UserName.Value);
// Args.Token.Claims.AddOrSet('scope', TSphinxUserEx(Args.User).Access_Level);
end;

I took out both to check if the issue lay here, and it did. It went through without a hitch with both removed. I tried it with just the preferred_username and it worked. Thus, I am happy with the code as is but may need the access level once I am more accomplished in applying the login methods.

Regards

Tom Dalton

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.