Sunday, March 11, 2012

Active directory + list users

I neet save user login form active direcotry to databases. How I can make that?

If you're using Trusted Security to connect to the database (In other words, every single user is authenticated to the database with their windows logon), you could write code like the following at the database level:

INSERT Users
(Username)
(SUSER_SNAME())

SUSER_SNAME, gives you the current authenticated user to the database.

If you're connecting to the database using a Sql Server Login, but are using windows authentication in your .net application you could write the following code:

Dim _sql as string
_sql = "INSERT Users (USERNAME) VALUES ('" + My.User.Name "')"

And just execute this code against the database.

Hope this helps,


No comments:

Post a Comment