I need to assign network service user to SQL Server database programmatically, so I am running this script:
USE [MyDB] GO DECLARE @user nvarchar(50) DECLARE @SQLStatement nvarchar(500) SET @user = SUSER_SNAME(0x010100000000000514000000); SET @SQLStatement = N'IF NOT EXISTS(SELECT principal_id FROM sys.database_principals WHERE name = ''' + @user + ''') BEGIN CREATE USER ' + quotename(@user) + ' FOR LOGIN ' + quotename(@user) + N' WITH DEFAULT_SCHEMA=[dbo] ALTER ROLE [db_owner] ADD MEMBER ' + quotename(@user) + ' END' EXEC sp_executesql @SQLStatement; GO
That does not work. The problem is that, when running
This is returned:
NT AUTHORITY\NETWORK SERVICE
That is wrong, since my system is in Spanish. When I add that user manually using SQL Server Manager and then I see the users in the database, that user is actually added as:
NT AUTHORITY\Servicio de red
Is there a way to add Network service account independent of language?