SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to insert IP Address in data table dynamically


How to insert IP Address in data table dynamically

Author
Message
anamika.singh282
anamika.singh282
Grasshopper
Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)Grasshopper (22 reputation)

Group: General Forum Members
Points: 22 Visits: 22
i have a store procedure for user login which i am calling in my ASP.NET code.And now i want that when user log, the IP Address of that user's system and date time of system will get saved into another table.i should be saved in 192.167.1.78 format. i have gone through your article but thats not fullfiling my need.please help me how can i do this.i tried this code which is not working. one thing i m not understanding as i am not very usuall with store procedure coding.what does exec dbo.xp_cmdshell'ipconfig' stand for.i mean what is "xp_cmdshell" and which dbo it is executing.
My code is:
ALTER PROCEDURE [dbo].[User_Login]
@username varchar(20),
@pword nvarchar(15),
@ipadress varchar(40) output,
@RS int output

AS

SELECT @RS = COUNT(*) FROM Users WHERE username=@username AND pword=@pword
BEGIN
DECLARE @ipLine varchar(200)
DECLARE @pos int
SET NOCOUNT ON
SET @ipaddress = NULL
CREATE TABLE LoginDetail(ipLine varchar(200))
INSERT INTO LoginDetail exec dbo.xp_cmdshell'ipconfig'
SELECT @ipLine = ipLine FROM LoginDeatil WHERE upper (ipLine) LIKE '%IP ADDRESS%'
IF (ISNULL (@ipLine,'***') != '***')
BEGIN
SET @pos = CharIndex(':',@ipLine,1);
SET @ipaddress = RTRIM(LTRIM(SUBSTRING (@ipLIne,@pos + 1,
LEN(@ipLine)-@pos)))
END
DROP TABLE LoginDeatin
SET NOCOUNT OFF
END
GO


i have to call this SP in my ASP.NET code.i dont want to display ip address and date time in front end.Only want to store ip and date time.
Lowell
Lowell
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28698 Visits: 39977
ipconfig will return information about the SERVER's NIC card...it would not have any information about the connecting users. that code might seem to work if your SQL server is also your development platform....if they are different, it would obviously not be accurate.

one of the data managment views (DMV) as the column sys.dm_exec_connections which is the connecting user's IP address; I'm not sure if you can use it in an logon audit trigger, I'd have to test that, but you can certainly use it inside a stored procedure or other statement after they've connected.


select
host_name(),
app_name(),
client_net_address
from sys.dm_exec_connections where session_id = @@spid




Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search