如何在SqlServer数据库的登录历史记录中存储计算机名称。 [英] How to store Computer Name in Login history of SqlServer database.

查看:230
本文介绍了如何在SqlServer数据库的登录历史记录中存储计算机名称。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,



我在ASp.net项目上工作,C#SqlServer 2005数据库。



我的项目开始页面是登录页面,登录后用户可以查看所有应用程序。现在好了。



我想把计算机名存储到我的登录历史表中。

在我的数据库表中我有字段作为LogId,UserName ,Login_Time,LogoutTime,Duration ....直到这里它存储完美。



如果用户登录和用户注销它存储在数据库中....它的罚款直到这里和商店在数据库中。



现在我想在这个Loginhistory表中存储ComputerName .....



LogId,ComputerName,UserName,Login_Time,Logout_Time,Duration



请您告诉我,用户登录后如何在数据库中存储/保存计算机名称。



提前致谢。

推荐答案

尝试使用以下声明< br $>


Try using below Statement

String ComputerName = Request.ServerVariables["REMOTE_HOST"]


EXECUTE sp_helpserver



实例将以[name]的形式提供。我建议像这样列表它们(伪代码):


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


Label1.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();





将此文本存储在数据库中。



store this text in database.


这篇关于如何在SqlServer数据库的登录历史记录中存储计算机名称。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆