vb.net - Handling AD Error When Not Connected -


i'm using below code logge don user's logon name. works fine when connected network/domain. when offline, error on 3rd line:

principalserverdownexception unhandled

the server not contacted.

private sub form1_load(sender object, e eventargs) handles mybase.load     dim currentaduser system.directoryservices.accountmanagement.userprincipal     currentaduser = system.directoryservices.accountmanagement.userprincipal.current     dim displayname string = currentaduser.givenname & " " & currentaduser.surname     label5.text = displayname     label4.text = getuserproperties() end sub 

how can check, , return userful error user, such "not on network" or "not connected domain", exit? i've tried below, gives same error:

private sub form1_load(sender object, e eventargs) handles mybase.load     dim currentaduser system.directoryservices.accountmanagement.userprincipal     if system.directoryservices.accountmanagement.userprincipal.current nothing         msgbox("network error: no connection domain")         application.exit()     else ....     end if end sub 

use try/catch

    try         dim currentaduser system.directoryservices.accountmanagement.userprincipal         currentaduser = system.directoryservices.accountmanagement.userprincipal.current         dim displayname string = currentaduser.givenname & " " & currentaduser.surname         label5.text = displayname         label4.text = getuserproperties()     catch ex exception         msgbox(...)     end try 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -