How can you retrieve the computer name of the person running a report?
I'm coming up blank here...how can I identify the computer of the person running an SRS report? If I query HOST_NAME() it gives me the host of the reporting server, not the person browsing.So, for example, Melissa opens a browser from computer named AAA to the SRS and pulls up her report. How do I get that report to show that the user is browsing from AAA?Thanks!Number2 - (John Nelson)Microsoft MVP - System Center Configuration Managerhttp://number2blog.com
October 9th, 2009 6:15pm

Hello John,AFAIK it's not possible the get the host name of the user.Host_Name() returns the host running the query and this is done by the reporting services.Olaf Helper ----------- * cogito ergo sum * errare humanum est * quote erat demonstrandum * Wenn ich denke, ist das ein Fehler und das beweise ich tglich http://olafhelper.over-blog.de
Free Windows Admin Tool Kit Click here and download it now
October 10th, 2009 8:28pm

Hi John, By default, there is no option to get the client’s IP and hostname from SQL Server Reporting Services reports. However, the SQL Server Reporting Services allow us the implement a custom function using Custom Code feature. So, to solve the issue, we can use the custom code function to retrieve the client’s IP and hostname. Here is a sample code for your reference: Public Function GetClientIP() As String Dim result as String result = System.Web.HttpContext.Current.Request.ServerVariables("REMOTE_ADDR") return result End Function Public Function GetClientHostName() As String Dim result as String result = System.Net.Dns.GetHostEntry(System.Web.HttpContext.Current.Request.ServerVariables("remote_addr")).HostName return result End Function To get the client’s IP, please use this expression in the report item: =Code. GetClientIP(). To get the client’s hostname, please use this expression in the report item: = Code. GetClientHostName() For more information, please see: Using Custom Code References in Expressions (Reporting Services): http://msdn.microsoft.com/en-us/library/ms155798.aspx If there is anything unclear, please feel free to ask. Thanks, Jin ChenJin Chen - MSFT
October 12th, 2009 2:15am

That's outstanding! Exactly what I was looking for. Thanks so much!Number2 - (John Nelson)Microsoft MVP - System Center Configuration Managerhttp://number2blog.com
Free Windows Admin Tool Kit Click here and download it now
October 12th, 2009 9:46am

hello experts, I'm new with Reporting Services 2008. Anybody show me how to use custom function using Custom Code feature? I've already created a Report Project in VSTS 2008. And I can not find where to past your code in the report. Following steps are what I've done: In the Solution Explorer -> right click the report -> choose view code woa there is XML only for report user interface. Many thanks for your help! khanhmy
October 14th, 2009 2:54am

hello experts again, I got it. Thanks khanhmy
Free Windows Admin Tool Kit Click here and download it now
October 14th, 2009 4:42am

Jin, Have you actually run the code you posted above from a report? I added a reference to System.Web, adjusted CAS in rssrvpolicy.config (on the server), RSPreviewPolicy.config (locally for BIDS) and tested the two functions posted above and they do not run. An #Error is returned when attempting to preview locally in BIDS as well as on the server. I added some try catch error handling and the error being thrown is: "Object reference not set to an instance of an object." Has anyone found a way to do this? Another approach that I've tried is with a custom assembly that uses the System.Net namespace to get the hostname but unfortunately it returns the hostname for the server not the client. ex: public static string GetClientHostName() { DnsPermission permission = new DnsPermission(System.Security.Permissions.PermissionState.Unrestricted); permission.Assert(); string retval = string.Empty; try { retval = Dns.GetHostName().ToString(); } catch (Exception ex) { retval = ex.Message.ToString(); } return retval; }
March 22nd, 2010 5:05pm

I assume you are using SQL server. I use this as one of the dataset of my report and display some of the columns on top of my report. It has some usefull information. Oracle does have the IP adress of the client. You can even makea view out of it and use it over and over. Hope it helps you. Sir Coder _______________________________________________________ SELECT DB_NAME() AS Database_Name, USER_NAME() AS User_Name, app_name() AS Application_Name, SERVERPROPERTY('servername') AS Server_Name, case SERVERPROPERTY('servername') when 'My_testServer_here' then 'Testing' when 'My_prod-server_name_here' then 'Production' else 'Unknown!!' end AS Server_Role, SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS Computer_Name, SERVERPROPERTY('InstanceName') AS Instance_Name, SERVERPROPERTY('Edition') as Server_edition,SERVERPROPERTY('ProductVersion') as ProductVersion ,SERVERPROPERTY('ProductLevel') as ProductLevel ,SERVERPROPERTY('MachineName') AS Machine_Name, GETDATE() AS Db_DateTime _____________________________________________________
Free Windows Admin Tool Kit Click here and download it now
March 22nd, 2010 7:26pm

Sir Coder, Thanks, that's a useful script but not quite what I'm looking for. It would be helpful to know if the code Jin posted really works and I'm getting something wrong when implementing it. If someone has figured out another approach that would work too.
March 23rd, 2010 8:40am

When I try implementing these functions, I get the following error in SSRS: Warning 1 [rsRuntimeErrorInExpression] The Value expression for the textrun Textbox1.Paragraphs[0].TextRuns[0] contains an error: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. C:\Users\dbug2\Documents\Visual Studio 2008\Projects\MSSQLRS\Report_ComputerName\Report_ComputerName\Main.rdl 0 0 Why is this?- Don
Free Windows Admin Tool Kit Click here and download it now
September 18th, 2012 9:33am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics