Convert a username to a SID string in C#/.NET

The podcast tells me I should ask, and answer, questions when they’re not answered on SO already. Here goes. The easy way, with .NET 2.0 and up, is this: NTAccount f = new NTAccount(“username”); SecurityIdentifier s = (SecurityIdentifier) f.Translate(typeof(SecurityIdentifier)); String sidString = s.ToString(); The hard way, which works when that won’t, and works on .NET … Read more

How can I convert from a SID to an account name in C#

See here for a good answer: The best way to resolve display username by SID? The gist of it is this bit: string sid=”S-1-5-21-789336058-507921405-854245398-9938″; string account = new System.Security.Principal.SecurityIdentifier(sid).Translate(typeof(System.Security.Principal.NTAccount)).ToString(); This approach works for me for non-local SID’s over the active directory.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)