SQL CLR Function and .NET Framework return different results

  • Hello, everyone.

    I have rather simple CLR function:

    [SqlFunction(IsDeterministic = true, DataAccess = DataAccessKind.None)]

    public static SqlString GetUserName()

    {

    return (SqlString)WindowsIdentity.GetCurrent().Name;

    }

    When I get result from .NET console app, I get correct answer "Jungle\Sektor". However, when SQL Server executes this code, it gives me "NT Service\MSSQL$SQL2014". How to get correct result? Thanks.

  • When you execute it from ssms it gives you the account under which the sql service is running.

    SELECT SUSER_SNAME() run from ssms should give you the same result as from your console .net app.

    Igor Micev,My blog: www.igormicev.com

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply