Retrieve the User ID at Run Time In a .NET Environment
November 12, 2008 Hey Mike
I am coding a .NET reporting application. The new .NET reports need to look like the old iSeries reports with the user name at the top. I am using the DB2 managed provider to connect to the data files.
My code for connecting is:
Public cni5 As iDB2Connection cni5 = New iDB2Connection("DataSource=" + My.Settings.PTCValue) cni5.Open()
When connecting, the .NET Windows application displays the Client Access sign-on screen just like the iSeries Access for Windows program does. I can see the connection on the iSeries side under the QUSRWRK Subsystem. It is called QZDASOINIT, user is QUSER, type is PJ (prestart job).
I have two questions:
1. How can I get the Work with Active Jobs screen to show the real user that signed on like I normally see when we use iSeries Access for Windows?
2. How can I get the user ID to use in my .NET application?
Are you on V5R4 yet? As of V5R4 the WRKACTJOB command shows the current user (i.e., the logged in user) instead of the job user as the default. Also, when QZDASOINIT jobs show QUSER as the current user it means they are not currently servicing any requests from a client (i.e., they’re asleep waiting for a request.) If your iSeries connection is only open for a short time, it may be difficult to see the signed-on user on this screen.
If you’re not on V5R4 yet, you can look for the QZDASOINIT jobs by user profile by issuing a WRKOBJLCK userid *USRPRF command. The only drawback is that you need to know the user name you’re looking for and the user must have an open connection in order for a QZDASOINIT job to show in the list of jobs. Other than this, your remaining options are to find a utility that lists active jobs with current user or write a program that uses the QUSRJOBI API to retrieve the list of jobs along with each job’s current user.
Now on to your second question. As for retrieving the user name in a client/server application, generically speaking, you can always retrieve the value of the CURRENT_USER register using SQL:
SELECT CURRENT_USER FROM SYSIBM/SYSDUMMY1
Specifically from a .NET application using the IBM managed provider, once the user has signed in and the connection has been opened, you can read the UserID property at run time from your iDB2Connection object as shown here:
Michael Sansoterra is a programmer/analyst for i3 Business Solutions, an IT services firm based in Grand Rapids, Michigan. Send your questions or comments for Michael to Ted Holt via the IT Jungle Contact page.