Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
Hi Experts,

Iam working on ASp.net Project , C# SqlServer 2005 Database.

My project start page is Login Page, after login User can view all the application. its fine now.

I want to Store Computer Name into My loginhistory table.
In my database table I have fields as LogId,UserName,Login_Time,LogoutTime,Duration....till here it is storing perfectly.

If user Logins and User Logouts it is stored in database....its fine till here and stores in database.

Now I want to store ComputerName in this Loginhistory Table.....as

LogId,ComputerName,UserName,Login_Time,Logout_Time,Duration

Please can you show me, how to store/save computer name in database after User login.

Thanks in advance.
Posted

Try using below Statement

C#
String ComputerName = Request.ServerVariables["REMOTE_HOST"]
 
Share this answer
 
v2
EXECUTE sp_helpserver

The instances will be available as [name]. I'd suggest tabulating them like this (pseudocode):
CREATE TABLE [cpqaAnswers].[cpqa].[tbl_RR_instanceName](
  [Idx][int]IDENTITY(1,1),
    [iName][nvarchar](256),
      [iNtwkName][nvarchar](257),
        [iStatus][nvarchar](258),
          [iId][int],
            [iCollatName][nvarchar](9),
              [iConnectTO][int](10),
                [iQueryTO][int](11)
    )
INSERT INTO [cpqaAnswers].[cpqa].[tbl_RR_instanceName]
   EXECUTE sp_helpserver

Then just use a string manipulator (pseudocode):
SELECT [Idx], [iName] FROM [cpqaAnswers].[cpqa].[tbl_RR_instanceName]

Know where the '\' is located by using this (pseudocode in a pseudo step):
CHARINDEX('\',[iName]) -- which'll return an integer "n" 

Then do the special query (pseudocode with pseudo variable):
SELECT LEFT([iName],"n") FROM [cpqaAnswers].[cpqa].[tbl_RR_instanceName]
  WHERE [Idx] = 1
 
Share this answer
 
C#
Label1.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();


store this text in database.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900