You have the ability to query the current user name in SQL Server using a basic Transact-SQL statement:
The problem you might eventually see is the incorrect name returned, if that users name was recently changed. Active Directory is a great product, but you might not understand why changing that persons name in AD (because of divorce, marriage, etc.) might not result in you seeing that new name in your SQL Server queries.
The explanation is simple, but it can be difficult to address.
The local security authority (LSA) caches the mapping between the SID and the user name in a local cache on the you SQL Server computer. The cached user name is not immediately synchronized with your domain controllers. The LSA on the SQL Server computer first queries the local SID cache. If an existing mapping is already in the local SID cache, the LSA returns the cached user name information instead of querying your domain controllers. This behavior is intended to improve performance.
The cache entries do time out, however chances are that recurring queries by applications keep the existing cache entry alive for the maximum lifetime of the cache entry.
If this turns out to be something that causing you issues in your environment, you can disable caching on your SQL Server instance, but you must also understand that will cause increased domain controller workload and network traffic.
To work around this issue, disable the local SID cache on the domain member computer. To do this, follow these steps:
- Open Registry Editor by typing regedit in the Start Search box, and then press ENTER.
- Locate and then right-click the following registry subkey:
- Point to New, and then click DWORD Value.
- Type LsaLookupCacheMaxSize, and then press ENTER.
- Right-click LsaLookupCacheMaxSize, and then click Modify.
- In the Value data box, type 0, and then click OK.
- Exit Registry Editor.