Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert mystery whith User SID to varChar

Status
Not open for further replies.

lechuck

Programmer
Sep 4, 2000
26
SE
I want to convert the user SID to varChar, I have successfully converted a local SQL users SID to varChar, se the code below.

Q: SELECT SUSER_SID('MyUser')
A: 0x15489420B0A30543B2CD88D4EE4E6C37

Q: SELECT SUSER_SNAME(0x15489420B0A30543B2CD88D4EE4E6C37)
A: MyUser

Q: SELECT Convert(varChar, SUSER_SID('MyUser'))
A: H" °£C²ÍˆÔîNl7

Q: SELECT SUSER_SNAME(SUSER_SID('MyUser'))
A: MyUser

Q: SELECT SUSER_SNAME(convert(varBinary, convert(varChar, SUSER_SID('MyUser'))))
A: MyUser

Q: SELECT SUSER_SNAME(convert(varBinary, 'H" °£C²ÍˆÔîNl7'))
A: MyUser


But when I'm using the same code for a NT user I get the following result:

Q: SELECT SUSER_SID('MYDOMAIN\NTUSER')
A: 0x01050000000000051500000092580A58DE26026F7B204646EF030000

Q: SELECT SUSER_SNAME(0x01050000000000051500000092580A58DE26026F7B204646EF030000)
A: MYDOMAIN\NTUSER

Q: SELECT Convert(varChar, SUSER_SID('MYDOMAIN\NTUSER'))
A: 

Q: SELECT SUSER_SNAME(SUSER_SID('MYDOMAIN\NTUSER'))
A: MYDOMAIN\NTUSER

Q: SELECT SUSER_SNAME(convert(varBinary, convert(varChar, SUSER_SID('MYDOMAIN\NTUSER'))))
A: MYDOMAIN\NTUSER

Q: SELECT SUSER_SNAME(convert(varBinary, ''))
A: NULL

Why is that?
I have tried with a few different NT Users but with the same result. Why can't I convert a NT Users SID to varChar?
 
I doubt this will resolve the problem but you may want to specify the size of the varchar in the convert statement. Is it possible that the value is larger than 50 characters long (which I believe is the default length of a varchar) and is therefore not converting correctly.

The only reason I suggest this is that I know I have had problems with other things where I did not specify the size of my varchar variables.

Good Luck! Crystal
crystalized_s@yahoo.com

--------------------------------------------------

Experience is one thing you can't get for nothing.

-Oscar Wilde

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top