S when you use custom Code When loading data to infopath, if:
An unhandled exception has occurred in the form's code
System. Security. securityexception
Request for the permission of Type 'Microsoft. Sharepoint. Security. sharepointpermission, Microsoft. Sharepoint. Security, version = 12.0.0.0, culture = neutral, publickeytoken = 71e9bce111e9429c' failed.
At system. Security. codeaccesssecurityengine. throwsecurityexception (Assembly ASM, permissionset granted, permissionset refused, runtimemethodhandle rmh, securityaction action, object demand, ipermission permthatfailed)
At system. Security. codeaccesssecurityengine. throwsecurityexception (Object assemblyorstring, permissionset granted, permissionset refused, runtimemethodhandle rmh, securityaction action, object demand, ipermission permthatfailed)
At system. Security. codeaccesssecurityengine. checksethelper (permissionset grants, permissionset refused, permissionset demands, runtimemethodhandle rmh, object assemblyorstring, securityaction action, Boolean throwexception)
At system. Security. codeaccesssecurityengine. checksethelper (compressedstack CS, permissionset grants, permissionset refused, permissionset demans, runtimemethodhandle rmh, assembly ASM, securityaction action Action)
At formusercodeloaddata. formcode. formevents_loading (Object sender, loadingeventargs E)
At Microsoft. Office. infopath. Internal. formeventshost. onload (docreturnevent pevent)
At Microsoft. Office. InterOP. infopath. semitrust. _ x?enteventsink2_sinkhelper.onload (docreturnevent pevent)
The most likely reason is that you have not set the trust level. You need to set it in the infopath form:
InToolsMenu, clickForm options.
InCategoryList, clickSecurity and trust.
InSecurity level, ClearAutomatically determine security level.
SelectFull TrustAnd then clickOK.