I have the following Trigger, what happens is that when wanting to retrieve the IP of the client machine, it takes the IP of the Application Server, someone who can help with a way to retrieve that IP, not the one of the application server.
ALTER trigger [dbo].[InsertLoginControl]
on [dbo].[Attendance]
for insert
as
declare @noEmpleado varchar(5)
DECLARE @IP_Address varchar(255)
declare @name varchar(50)
declare @pass varchar(50)
declare @LastCon datetime
select top 1 @noEmpleado = EmpNo from Attendance order by idAttendance desc
SELECT @IP_Address =
convert(varchar(20),CONNECTIONPROPERTY('client_net_address'))
select top 1 @name = NameDisplay from Login_empl where
EmployeeNo=@noEmpleado
select top 1 @pass = UserPAss from Login where Emp_Number=@noEmpleado
select top 1 @LastCon=DateLogout from logincontrol where
empNumber=@noEmpleado order by id desc
if exists(select empNumber from LoginControl where empNumber= @noEmpleado)
begin
if(@LastCon is null)
begin
update LoginControl set DateLogout=getdate() where empNumber=@noEmpleado
insert into LoginControl
values(@IP_Address,getdate(),null,@noEmpleado,@name,
ENCRYPTBYPASSPHRASE('BCPPlus2019', @pass))
end
else
begin
insert into LoginControl
values(@IP_Address,getdate(),null,@noEmpleado,@name,
ENCRYPTBYPASSPHRASE('BCPPlus2019', @pass))
end
end
else
begin
insert into LoginControl
values(@IP_Address,getdate(),null,@noEmpleado,@name,
ENCRYPTBYPASSPHRASE('BCPPlus2019', @pass))
end