如何以字符串格式检索sql server SID?

Meh*_*ard 2 sql sid bytearray converter

你好我今天早上试图用SQl查询检索我的计算机的SID.我只能在Byte数组中检索SID!

是否可以使用强制转换检索字符串?我试过但不可能.

这是我的SQL查询

SqlDataSource data = new SqlDataSource(
System.Configuration.ConfigurationManager.ConnectionStrings["myDbConnection"].ToString(), 
"Select sid FROM sys.server_principals where Name='##MS_SQLAuthenticatorCertificate##'");

DataView viewData = data.Select(DataSourceSelectArguments.Empty) as DataView;

//Get S.I.D in byte
byte[] tabSid = (byte[]) viewData[0][0] ;
//Get S.I.D in String format (not working)
string varSid = viewData[0][0].toString() ;
Run Code Online (Sandbox Code Playgroud)

非常感谢

Avi*_*tus 5

如果你这样做:

SELECT master.dbo.fn_varbintohexstr(sid)  AS 'SID'
 FROM sys.server_principals where Name='##MS_SQLAuthenticatorCertificate##'
Run Code Online (Sandbox Code Playgroud)

然后.ToString()将正常工作